Changeset View
Changeset View
Standalone View
Standalone View
kcm/kcm.cpp
Show First 20 Lines • Show All 94 Lines • ▼ Show 20 Line(s) | 67 | { | |||
---|---|---|---|---|---|
95 | connect(rootItem, SIGNAL(requestExportConnection(QString)), this, SLOT(onRequestExportConnection(QString))); | 95 | connect(rootItem, SIGNAL(requestExportConnection(QString)), this, SLOT(onRequestExportConnection(QString))); | ||
96 | connect(rootItem, SIGNAL(requestToChangeConnection(QString,QString)), this, SLOT(onRequestToChangeConnection(QString,QString))); | 96 | connect(rootItem, SIGNAL(requestToChangeConnection(QString,QString)), this, SLOT(onRequestToChangeConnection(QString,QString))); | ||
97 | 97 | | |||
98 | QVBoxLayout *l = new QVBoxLayout(this); | 98 | QVBoxLayout *l = new QVBoxLayout(this); | ||
99 | l->addWidget(mainWidget); | 99 | l->addWidget(mainWidget); | ||
100 | 100 | | |||
101 | setButtons(Button::Apply); | 101 | setButtons(Button::Apply); | ||
102 | 102 | | |||
103 | // Pre-select currently active primary connection and if there is none then just select | 103 | NetworkManager::Connection::Ptr selectedConnection; | ||
104 | // the very first connection | 104 | | ||
105 | // Look in the arguments for a connection ID to preselect | ||||
106 | static const QLatin1Literal uuidArgumentMarker { "Uuid=" }; | ||||
107 | for (QVariant arg : args) { | ||||
108 | if (arg.canConvert(QMetaType::QString)) { | ||||
109 | QString uuid = arg.toString(); | ||||
110 | if (uuid.startsWith(uuidArgumentMarker)) { | ||||
111 | uuid = uuid.replace(uuidArgumentMarker, QString()); | ||||
112 | selectedConnection = NetworkManager::findConnectionByUuid(uuid); | ||||
113 | qDebug() << "Selecting user connection:" << uuid; | ||||
114 | break; | ||||
115 | } | ||||
116 | } | ||||
117 | } | ||||
118 | | ||||
119 | // Pre-select the currently active primary connection | ||||
120 | if (!selectedConnection || !selectedConnection->isValid()) { | ||||
105 | NetworkManager::ActiveConnection::Ptr activeConnection = NetworkManager::primaryConnection(); | 121 | NetworkManager::ActiveConnection::Ptr activeConnection = NetworkManager::primaryConnection(); | ||
106 | if (activeConnection && activeConnection->isValid()) { | 122 | if (activeConnection && activeConnection->isValid()) { | ||
107 | // Also check if the connection type is supported by KCM | 123 | selectedConnection = activeConnection->connection(); | ||
108 | const NetworkManager::ConnectionSettings::ConnectionType type = activeConnection->type(); | 124 | qDebug() << "Selecting active connection:" << selectedConnection->uuid(); | ||
109 | if (UiUtils::isConnectionTypeSupported(type)) { | | |||
110 | QMetaObject::invokeMethod(rootItem, "selectConnection", Q_ARG(QVariant, activeConnection->id()), Q_ARG(QVariant, activeConnection->connection()->path())); | | |||
111 | } | 125 | } | ||
112 | } else { | 126 | } | ||
113 | // Select first connection | 127 | | ||
128 | // Select the very first connection as a fallback | ||||
129 | if (!selectedConnection || !selectedConnection->isValid()) { | ||||
114 | NetworkManager::Connection::List connectionList = NetworkManager::listConnections(); | 130 | NetworkManager::Connection::List connectionList = NetworkManager::listConnections(); | ||
115 | std::sort(connectionList.begin(), connectionList.end(), [] (const NetworkManager::Connection::Ptr &left, const NetworkManager::Connection::Ptr &right) | 131 | std::sort(connectionList.begin(), connectionList.end(), [] (const NetworkManager::Connection::Ptr &left, const NetworkManager::Connection::Ptr &right) | ||
116 | { | 132 | { | ||
117 | const QString leftName = left->settings()->id(); | 133 | const QString leftName = left->settings()->id(); | ||
118 | const UiUtils::SortedConnectionType leftType = UiUtils::connectionTypeToSortedType(left->settings()->connectionType()); | 134 | const UiUtils::SortedConnectionType leftType = UiUtils::connectionTypeToSortedType(left->settings()->connectionType()); | ||
119 | const QDateTime leftDate = left->settings()->timestamp(); | 135 | const QDateTime leftDate = left->settings()->timestamp(); | ||
120 | 136 | | |||
121 | const QString rightName = right->settings()->id(); | 137 | const QString rightName = right->settings()->id(); | ||
Show All 17 Lines | |||||
139 | } else { | 155 | } else { | ||
140 | return false; | 156 | return false; | ||
141 | } | 157 | } | ||
142 | }); | 158 | }); | ||
143 | 159 | | |||
144 | Q_FOREACH (const NetworkManager::Connection::Ptr &connection, connectionList) { | 160 | Q_FOREACH (const NetworkManager::Connection::Ptr &connection, connectionList) { | ||
145 | const NetworkManager::ConnectionSettings::ConnectionType type = connection->settings()->connectionType(); | 161 | const NetworkManager::ConnectionSettings::ConnectionType type = connection->settings()->connectionType(); | ||
146 | if (UiUtils::isConnectionTypeSupported(type)) { | 162 | if (UiUtils::isConnectionTypeSupported(type)) { | ||
147 | QMetaObject::invokeMethod(rootItem, "selectConnection", Q_ARG(QVariant, connection->settings()->id()), Q_ARG(QVariant, connection->path())); | 163 | selectedConnection = connection; | ||
164 | qDebug() << "Selecting first connection:" << connection->uuid(); | ||||
148 | break; | 165 | break; | ||
149 | } | 166 | } | ||
150 | } | 167 | } | ||
151 | } | 168 | } | ||
152 | 169 | | |||
170 | if (selectedConnection && selectedConnection->isValid()) { | ||||
171 | const NetworkManager::ConnectionSettings::Ptr settings = selectedConnection->settings(); | ||||
172 | if (UiUtils::isConnectionTypeSupported(settings->connectionType())) { | ||||
173 | QMetaObject::invokeMethod(rootItem, "selectConnection", Q_ARG(QVariant, settings->id()), Q_ARG(QVariant, selectedConnection->path())); | ||||
174 | } | ||||
175 | } else { | ||||
176 | qDebug() << "Cannot preselect a connection"; | ||||
177 | } | ||||
178 | | ||||
153 | connect(NetworkManager::settingsNotifier(), &NetworkManager::SettingsNotifier::connectionAdded, this, &KCMNetworkmanagement::onConnectionAdded, Qt::UniqueConnection); | 179 | connect(NetworkManager::settingsNotifier(), &NetworkManager::SettingsNotifier::connectionAdded, this, &KCMNetworkmanagement::onConnectionAdded, Qt::UniqueConnection); | ||
154 | 180 | | |||
155 | // Initialize first scan and then scan every 15 seconds | 181 | // Initialize first scan and then scan every 15 seconds | ||
156 | m_handler->requestScan(); | 182 | m_handler->requestScan(); | ||
157 | 183 | | |||
158 | m_timer = new QTimer(this); | 184 | m_timer = new QTimer(this); | ||
159 | m_timer->setInterval(15000); | 185 | m_timer->setInterval(15000); | ||
160 | connect(m_timer, &QTimer::timeout, [this] () { | 186 | connect(m_timer, &QTimer::timeout, [this] () { | ||
▲ Show 20 Lines • Show All 364 Lines • Show Last 20 Lines |