MailTransport

transportcombobox.cpp
1/*
2 SPDX-FileCopyrightText: 2006-2007 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "transportcombobox.h"
8#include "transportmanager.h"
9#include "transportmodel.h"
10#include "transportsortproxymodel.h"
11
12using namespace MailTransport;
13
14/**
15 * Private class that helps to provide binary compatibility between releases.
16 * @internal
17 */
18class TransportComboBoxPrivate
19{
20public:
21 TransportComboBoxPrivate(TransportComboBox *qq)
22 : q(qq)
23 , transportModel(new MailTransport::TransportModel(qq))
24 , transportProxyModel(new MailTransport::TransportSortProxyModel(qq))
25 {
26 transportProxyModel->setSourceModel(transportModel);
27 q->setModel(transportProxyModel);
28 }
29 void updateComboboxList()
30 {
31 const int oldTransport = q->currentTransportId();
32 q->clear();
33
34 int defaultId = 0;
35 if (!TransportManager::self()->isEmpty()) {
37 }
38
39 if (oldTransport != -1) {
40 q->setCurrentTransport(oldTransport);
41 } else {
42 q->setCurrentTransport(defaultId);
43 }
44 }
45 TransportComboBox *const q;
46 MailTransport::TransportModel *const transportModel;
47 MailTransport::TransportSortProxyModel *const transportProxyModel;
48};
49
51 : QComboBox(parent)
52 , d(new TransportComboBoxPrivate(this))
53{
54 d->updateComboboxList();
55 connect(TransportManager::self(), &TransportManager::transportRemoved, this, &TransportComboBox::transportRemoved);
56 setModelColumn(MailTransport::TransportModel::NameRole);
57}
58
59TransportComboBox::~TransportComboBox() = default;
60
62{
63 return d->transportProxyModel->mapToSource(d->transportProxyModel->index(currentIndex(), MailTransport::TransportModel::TransportIdentifierRole))
64 .data()
65 .toInt();
66}
67
69{
70 const int idx = d->transportModel->indexOf(transportId);
71 if (idx != -1) {
72 const int newIndex = d->transportProxyModel->mapFromSource(d->transportModel->index(idx, MailTransport::TransportModel::TransportIdentifierRole)).row();
73 setCurrentIndex(newIndex);
74 return true;
75 }
76 return false;
77}
78
83
84TransportActivitiesAbstract *TransportComboBox::transportActivitiesAbstract() const
85{
86 return d->transportProxyModel->transportActivitiesAbstract();
87}
88
89void TransportComboBox::setTransportActivitiesAbstract(TransportActivitiesAbstract *activitiesAbstract)
90{
91 d->transportProxyModel->setTransportActivitiesAbstract(activitiesAbstract);
92}
93
94bool TransportComboBox::enablePlasmaActivities() const
95{
96 return d->transportProxyModel->enablePlasmaActivities();
97}
98
99void TransportComboBox::setEnablePlasmaActivities(bool newEnablePlasmaActivities)
100{
101 d->transportProxyModel->setEnablePlasmaActivities(newEnablePlasmaActivities);
102}
103
104#include "moc_transportcombobox.cpp"
A combo-box for selecting a mail transport.
TransportComboBox(QWidget *parent=nullptr)
Creates a new mail transport selection combo box.
bool setCurrentTransport(int transportId)
Selects the given transport.
MailTransport::TransportActivitiesAbstract * transportActivitiesAbstract() const
void setTransportActivitiesAbstract(MailTransport::TransportActivitiesAbstract *activitiesAbstract)
int currentTransportId() const
Returns identifier of the currently selected mail transport.
QString transportType() const
Returns the type of the selected transport.
void transportRemoved(int id, const QString &name)
Emitted when a transport is deleted.
Transport * transportById(Transport::Id id, bool def=true) const
Returns the Transport object with the given id.
static TransportManager * self()
Returns the TransportManager instance.
Q_SCRIPTABLE int defaultTransportId() const
Returns the default transport identifier.
void clear()
void setModelColumn(int visibleColumn)
virtual void setModel(QAbstractItemModel *model)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
virtual void setSourceModel(QAbstractItemModel *sourceModel) override
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:07:33 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.