MailTransport

transportcombobox.cpp
1 /*
2  SPDX-FileCopyrightText: 2006-2007 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "transportcombobox.h"
8 #include "transport.h"
9 #include "transportmanager.h"
10 
11 using namespace MailTransport;
12 
13 /**
14  * Private class that helps to provide binary compatibility between releases.
15  * @internal
16  */
17 class TransportComboBoxPrivate
18 {
19 public:
20  QVector<int> transports;
21 };
22 
24  : QComboBox(parent)
25  , d(new TransportComboBoxPrivate)
26 {
29  connect(TransportManager::self(), &TransportManager::transportRemoved, this, &TransportComboBox::transportRemoved);
30 }
31 
32 TransportComboBox::~TransportComboBox() = default;
33 
35 {
36  if (currentIndex() >= 0 && currentIndex() < d->transports.count()) {
37  return d->transports.at(currentIndex());
38  }
39  return -1;
40 }
41 
43 {
44  const int i = d->transports.indexOf(transportId);
45  if (i >= 0 && i < count()) {
46  setCurrentIndex(i);
47  return true;
48  }
49  return false;
50 }
51 
53 {
54  return TransportManager::self()->transportById(currentTransportId())->identifier();
55 }
56 
58 {
59  const int oldTransport = currentTransportId();
60  clear();
61 
62  int defaultId = 0;
63  if (!TransportManager::self()->isEmpty()) {
64  const QStringList listNames = TransportManager::self()->transportNames();
66  addItems(listNames);
67  setTransportList(listIds);
69  }
70 
71  if (oldTransport != -1) {
72  setCurrentTransport(oldTransport);
73  } else {
74  setCurrentTransport(defaultId);
75  }
76 }
77 
78 void TransportComboBox::setTransportList(const QVector<int> &transportList)
79 {
80  d->transports = transportList;
81 }
Q_SCRIPTABLE int defaultTransportId() const
Returns the default transport identifier.
Transport * transportById(int id, bool def=true) const
Returns the Transport object with the given id.
bool setCurrentTransport(int transportId)
Selects the given transport.
Q_SCRIPTABLE void transportsChanged()
Emitted when transport settings have changed (by this or any other TransportManager instance).
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
int currentTransportId() const
Returns identifier of the currently selected mail transport.
Q_SCRIPTABLE QVector< int > transportIds() const
Returns a list of transport identifiers.
TransportComboBox(QWidget *parent=nullptr)
Creates a new mail transport selection combo box.
void addItems(const QStringList &texts)
Q_SCRIPTABLE QStringList transportNames() const
Returns a list of transport names.
static TransportManager * self()
Returns the TransportManager instance.
void clear()
void transportRemoved(int id, const QString &name)
Emitted when a transport is deleted.
QString transportType() const
Returns the type of the selected transport.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Mar 23 2023 04:19:12 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.