Commit 44b5d5f4 authored by Jan Grulich's avatar Jan Grulich
Browse files

Initial port of QML editor

parent 895602f2
......@@ -87,7 +87,8 @@ if (WITH_MODEMMANAGER_SUPPORT)
endif()
add_subdirectory(applet)
add_subdirectory(editor)
# add_subdirectory(editor)
add_subdirectory(editor-qml)
add_subdirectory(kded)
add_subdirectory(libs)
add_subdirectory(settings)
......
......@@ -71,7 +71,7 @@ FocusScope {
currentIndex: -1;
interactive: true;
boundsBehavior: Flickable.StopAtBounds;
section.property: showSections ? "Section" : "";
section.property: showSections ? "AppletSection" : "";
section.delegate: Header { text: section }
delegate: ConnectionItem {
onStateChanged: {
......
set(plasmanetworkmanagement-internal_SRCS
models/appletproxymodel.cpp
models/editoridentitymodel.cpp
# models/editoridentitymodel.cpp
models/editorproxymodel.cpp
models/networkitemslist.cpp
models/networkmodel.cpp
......
......@@ -30,6 +30,7 @@
// #include "trafficmonitor.h"
#include "appletproxymodel.h"
#include "editorproxymodel.h"
#include "networkmodel.h"
#include "handler.h"
......@@ -55,6 +56,8 @@ void QmlPlugins::registerTypes(const char* uri)
qmlRegisterType<NetworkModel>(uri, 0, 1, "NetworkModel");
// @uri org.kde.plasma.networkmanagement.AppletProxyModel
qmlRegisterType<AppletProxyModel>(uri, 0, 1, "AppletProxyModel");
// @uri org.kde.plasma.networkmanagement.AppletProxyModel
qmlRegisterType<EditorProxyModel>(uri, 0, 1, "EditorProxyModel");
// @uri org.kde.plasma.networkmanagement.TrafficMonitor
// qmlRegisterType<TrafficMonitor>(uri, 0, 1, "TrafficMonitor");
}
......
......@@ -63,15 +63,15 @@
using namespace NetworkManager;
ConnectionDetailEditor::ConnectionDetailEditor(NetworkManager::ConnectionSettings::ConnectionType type, QWidget* parent,
const QString &masterUuid, const QString &slaveType, Qt::WindowFlags f):
QDialog(parent, f),
m_ui(new Ui::ConnectionDetailEditor),
m_connection(new NetworkManager::ConnectionSettings(type)),
m_numSecrets(0),
m_new(true),
m_masterUuid(masterUuid),
m_slaveType(slaveType)
ConnectionDetailEditor::ConnectionDetailEditor(NetworkManager::ConnectionSettings::ConnectionType type,
const QString &masterUuid, const QString &slaveType, QWidget* parent, Qt::WindowFlags f)
: QDialog(parent, f)
, m_ui(new Ui::ConnectionDetailEditor)
, m_connection(new NetworkManager::ConnectionSettings(type))
, m_numSecrets(0)
, m_new(true)
, m_masterUuid(masterUuid)
, m_slaveType(slaveType)
{
setAttribute(Qt::WA_DeleteOnClose);
m_ui->setupUi(this);
......@@ -79,14 +79,14 @@ ConnectionDetailEditor::ConnectionDetailEditor(NetworkManager::ConnectionSetting
initEditor();
}
ConnectionDetailEditor::ConnectionDetailEditor(NetworkManager::ConnectionSettings::ConnectionType type, QWidget* parent,
const QString &vpnType, bool shared, Qt::WindowFlags f):
QDialog(parent, f),
m_ui(new Ui::ConnectionDetailEditor),
m_connection(new NetworkManager::ConnectionSettings(type)),
m_numSecrets(0),
m_new(true),
m_vpnType(vpnType)
ConnectionDetailEditor::ConnectionDetailEditor(NetworkManager::ConnectionSettings::ConnectionType type,
const QString &vpnType, bool shared, QWidget* parent, Qt::WindowFlags f)
: QDialog(parent, f)
, m_ui(new Ui::ConnectionDetailEditor)
, m_connection(new NetworkManager::ConnectionSettings(type))
, m_numSecrets(0)
, m_new(true)
, m_vpnType(vpnType)
{
setAttribute(Qt::WA_DeleteOnClose);
m_ui->setupUi(this);
......@@ -117,12 +117,12 @@ ConnectionDetailEditor::ConnectionDetailEditor(NetworkManager::ConnectionSetting
initEditor();
}
ConnectionDetailEditor::ConnectionDetailEditor(ConnectionSettings::ConnectionType type, const QVariantList &args, QWidget *parent, Qt::WindowFlags f):
QDialog(parent, f),
m_ui(new Ui::ConnectionDetailEditor),
m_connection(new NetworkManager::ConnectionSettings(type)),
m_numSecrets(0),
m_new(true)
ConnectionDetailEditor::ConnectionDetailEditor(ConnectionSettings::ConnectionType type, const QVariantList &args, QWidget *parent, Qt::WindowFlags f)
: QDialog(parent, f)
, m_ui(new Ui::ConnectionDetailEditor)
, m_connection(new NetworkManager::ConnectionSettings(type))
, m_numSecrets(0)
, m_new(true)
{
setAttribute(Qt::WA_DeleteOnClose);
m_ui->setupUi(this);
......@@ -164,14 +164,14 @@ ConnectionDetailEditor::ConnectionDetailEditor(ConnectionSettings::ConnectionTyp
}
ConnectionDetailEditor::ConnectionDetailEditor(const NetworkManager::ConnectionSettings::Ptr &connection, QWidget* parent, Qt::WindowFlags f, bool newConnection):
QDialog(parent, f),
m_ui(new Ui::ConnectionDetailEditor),
m_connection(connection),
m_numSecrets(0),
m_new(newConnection),
m_masterUuid(connection->master()),
m_slaveType(connection->slaveType())
ConnectionDetailEditor::ConnectionDetailEditor(const NetworkManager::ConnectionSettings::Ptr &connection, bool newConnection, QWidget* parent, Qt::WindowFlags f)
: QDialog(parent, f)
, m_ui(new Ui::ConnectionDetailEditor)
, m_connection(connection)
, m_numSecrets(0)
, m_new(newConnection)
, m_masterUuid(connection->master())
, m_slaveType(connection->slaveType())
{
setAttribute(Qt::WA_DeleteOnClose);
m_ui->setupUi(this);
......
......@@ -38,17 +38,17 @@ class PLASMA_NM_EXPORT ConnectionDetailEditor : public QDialog
public:
explicit ConnectionDetailEditor(NetworkManager::ConnectionSettings::ConnectionType type,
QWidget* parent = 0,
const QString &masterUuid = QString(),
const QString &slaveType = QString(),
QWidget* parent = 0,
Qt::WindowFlags f = 0);
explicit ConnectionDetailEditor(NetworkManager::ConnectionSettings::ConnectionType type,
QWidget* parent = 0,
const QString &vpnType = QString(),
bool shared = false,
QWidget* parent = 0,
Qt::WindowFlags f = 0);
explicit ConnectionDetailEditor(const NetworkManager::ConnectionSettings::Ptr &connection,
QWidget* parent = 0, Qt::WindowFlags f = 0, bool newConnection = false);
bool newConnection = false, QWidget* parent = 0, Qt::WindowFlags f = 0);
explicit ConnectionDetailEditor(NetworkManager::ConnectionSettings::ConnectionType type,
const QVariantList &args,
QWidget* parent = 0, Qt::WindowFlags f = 0);
......
......@@ -168,7 +168,7 @@ void BondWidget::addBond(QAction *action)
qDebug() << "Slave type:" << type();
QPointer<ConnectionDetailEditor> bondEditor = new ConnectionDetailEditor(NetworkManager::ConnectionSettings::ConnectionType(action->data().toInt()),
this, m_uuid, type());
m_uuid, type(), this);
if (bondEditor->exec() == QDialog::Accepted) {
qDebug() << "Saving slave connection";
connect(NetworkManager::settingsNotifier(), SIGNAL(connectionAddComplete(QString,bool,QString)),
......
......@@ -118,7 +118,7 @@ void BridgeWidget::addBridge(QAction *action)
qDebug() << "Slave type:" << type();
QPointer<ConnectionDetailEditor> bridgeEditor = new ConnectionDetailEditor(NetworkManager::ConnectionSettings::ConnectionType(action->data().toInt()),
this, m_uuid, type());
m_uuid, type(), this);
if (bridgeEditor->exec() == QDialog::Accepted) {
qDebug() << "Saving slave connection";
connect(NetworkManager::settingsNotifier(), SIGNAL(connectionAddComplete(QString,bool,QString)),
......
......@@ -107,7 +107,7 @@ void TeamWidget::addTeam(QAction *action)
qDebug() << "Slave type:" << type();
QPointer<ConnectionDetailEditor> teamEditor = new ConnectionDetailEditor(NetworkManager::ConnectionSettings::ConnectionType(action->data().toInt()),
this, m_uuid, type());
m_uuid, type(), this);
if (teamEditor->exec() == QDialog::Accepted) {
qDebug() << "Saving slave connection";
connect(NetworkManager::settingsNotifier(), SIGNAL(connectionAddComplete(QString,bool,QString)),
......
......@@ -147,7 +147,7 @@ void Handler::addAndActivateConnection(const QString& device, const QString& spe
m_tmpDevicePath = device;
m_tmpSpecificPath = specificObject;
QPointer<ConnectionDetailEditor> editor = new ConnectionDetailEditor(settings, 0, 0, true);
QPointer<ConnectionDetailEditor> editor = new ConnectionDetailEditor(settings, true);
editor->show();
KWindowSystem::setState(editor->winId(), NET::KeepAbove);
KWindowSystem::forceActiveWindow(editor->winId());
......
......@@ -78,7 +78,6 @@ AppletProxyModel::SortedConnectionType AppletProxyModel::connectionTypeToSortedT
AppletProxyModel::AppletProxyModel(QObject* parent)
: QSortFilterProxyModel(parent)
{
// TODO
setDynamicSortFilter(true);
sort(0, Qt::DescendingOrder);
}
......
......@@ -79,7 +79,7 @@ QVariant EditorIdentityModel::data(const QModelIndex& index, int role) const
== NetworkManager::ActiveConnection::Activated;
NetworkManager::ConnectionSettings::ConnectionType type = static_cast<NetworkManager::ConnectionSettings::ConnectionType>(sourceModel()->data(sourceIndex, NetworkModel::TypeRole).toInt());
QString tooltip;
QString iconName = UiUtils::iconAndTitleForConnectionSettingsType(type, tooltip);
QString iconName = "foo";
const int column = index.column();
if (role == Qt::DisplayRole) {
......
/*
Copyright 2013 Jan Grulich <jgrulich@redhat.com>
Copyright 2013-2014 Jan Grulich <jgrulich@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -19,9 +19,62 @@
*/
#include "editorproxymodel.h"
#include "networkmodelitem.h"
#include "networkmodel.h"
EditorProxyModel::SortedConnectionType EditorProxyModel::connectionTypeToSortedType(NetworkManager::ConnectionSettings::ConnectionType type)
{
switch (type) {
case NetworkManager::ConnectionSettings::Unknown:
return EditorProxyModel::EditorProxyModel::Unknown;
break;
case NetworkManager::ConnectionSettings::Adsl:
return EditorProxyModel::EditorProxyModel::Adsl;
break;
case NetworkManager::ConnectionSettings::Bluetooth:
return EditorProxyModel::Bluetooth;
break;
case NetworkManager::ConnectionSettings::Bond:
return EditorProxyModel::Bond;
break;
case NetworkManager::ConnectionSettings::Bridge:
return EditorProxyModel::Bridge;
break;
case NetworkManager::ConnectionSettings::Cdma:
return EditorProxyModel::Cdma;
break;
case NetworkManager::ConnectionSettings::Gsm:
return EditorProxyModel::Gsm;
break;
case NetworkManager::ConnectionSettings::Infiniband:
return EditorProxyModel::Infiniband;
break;
case NetworkManager::ConnectionSettings::OLPCMesh:
return EditorProxyModel::OLPCMesh;
break;
case NetworkManager::ConnectionSettings::Pppoe:
return EditorProxyModel::Pppoe;
break;
case NetworkManager::ConnectionSettings::Vlan:
return EditorProxyModel::Vlan;
break;
case NetworkManager::ConnectionSettings::Vpn:
return EditorProxyModel::Vpn;
break;
case NetworkManager::ConnectionSettings::Wimax:
return EditorProxyModel::Wimax;
break;
case NetworkManager::ConnectionSettings::Wired:
return EditorProxyModel::Wired;
break;
case NetworkManager::ConnectionSettings::Wireless:
return EditorProxyModel::Wireless;
break;
default:
return EditorProxyModel::Unknown;
break;
}
}
EditorProxyModel::EditorProxyModel(QObject* parent)
: QSortFilterProxyModel(parent)
{
......@@ -35,6 +88,75 @@ EditorProxyModel::~EditorProxyModel()
{
}
void EditorProxyModel::setSortOrder(Qt::SortOrder order)
{
sort(0, order);
}
void EditorProxyModel::setSortRole(const QByteArray& role)
{
QSortFilterProxyModel::setSortRole(roleKey(role));
}
QByteArray EditorProxyModel::sortRole() const
{
return roleNames().value(QSortFilterProxyModel::sortRole());
}
QString EditorProxyModel::filterString() const
{
return filterRegExp().pattern();
}
void EditorProxyModel::setFilterString(const QString& filter)
{
setFilterRegExp(QRegExp(filter, filterCaseSensitivity()));
}
QVariant EditorProxyModel::get(int row, const QString& role)
{
QModelIndex index = EditorProxyModel::index(row, 0);
if (role == QLatin1String("ConnectionPath")) {
return data(index, NetworkModel::ConnectionPathRole);
} else if (role == QLatin1String("ConnectionState")) {
return data(index, NetworkModel::ConnectionStateRole);
} else if (role == QLatin1String("DevicePath")) {
return data(index, NetworkModel::DevicePathRole);
} else if (role == QLatin1String("ItemType")) {
return data(index, NetworkModel::ItemTypeRole);
} else if (role == QLatin1String("Name")) {
return data(index, NetworkModel::NameRole);
} else if (role == QLatin1String("TypeIcon")) {
return data(index, NetworkModel::TypeIconRole);
} else if (role == QLatin1String("SpecificPath")) {
return data(index, NetworkModel::SpecificPathRole);
} else if (role == QLatin1String("Uuid")) {
return data(index, NetworkModel::UuidRole);
}
return QVariant();
}
int EditorProxyModel::roleKey(const QByteArray &role) const
{
QHash<int, QByteArray> roles = roleNames();
QHashIterator<int, QByteArray> it(roles);
while (it.hasNext()) {
it.next();
if (it.value() == role)
return it.key();
}
return -1;
}
QHash<int, QByteArray> EditorProxyModel::roleNames() const
{
if (QAbstractItemModel *source = sourceModel())
return source->roleNames();
return QHash<int, QByteArray>();
}
bool EditorProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
{
const QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
......@@ -54,7 +176,7 @@ bool EditorProxyModel::filterAcceptsRow(int source_row, const QModelIndex& sourc
const QString pattern = filterRegExp().pattern();
if (!pattern.isEmpty()) { // filtering on data (connection name), wildcard-only
const QString data = sourceModel()->data(index, Qt::DisplayRole).toString();
const QString data = sourceModel()->data(index, NetworkModel::NameRole).toString();
//qDebug() << "Filtering " << data << "with pattern" << pattern;
return data.contains(pattern, Qt::CaseInsensitive);
}
......@@ -64,12 +186,13 @@ bool EditorProxyModel::filterAcceptsRow(int source_row, const QModelIndex& sourc
bool EditorProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
if (sourceModel()) { // special sorting case, only for editor
if (sortColumn() == 1) {
const QDateTime leftDate = sourceModel()->data(left, NetworkModel::TimeStampRole).toDateTime();
const QDateTime rightDate = sourceModel()->data(right, NetworkModel::TimeStampRole).toDateTime();
return leftDate < rightDate;
}
const SortedConnectionType leftType = connectionTypeToSortedType((NetworkManager::ConnectionSettings::ConnectionType) sourceModel()->data(left, NetworkModel::TypeRole).toUInt());
const SortedConnectionType rightType = connectionTypeToSortedType((NetworkManager::ConnectionSettings::ConnectionType) sourceModel()->data(right, NetworkModel::TypeRole).toUInt());
if (sortOrder() == Qt::DescendingOrder && leftType != rightType) {
return (leftType > rightType);
} else if (leftType != rightType) {
return (leftType < rightType);
}
return QSortFilterProxyModel::lessThan(left, right);
......
......@@ -23,17 +23,37 @@
#include <QSortFilterProxyModel>
#include "plasmanm_export.h"
#include "networkmodelitem.h"
class PLASMA_NM_EXPORT EditorProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
Q_PROPERTY(QAbstractItemModel * sourceModel READ sourceModel WRITE setSourceModel)
Q_PROPERTY(QByteArray sortRole READ sortRole WRITE setSortRole)
Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder)
Q_PROPERTY(QString filterString READ filterString WRITE setFilterString)
public:
enum SortedConnectionType {Wired, Wireless, Wimax, Gsm, Cdma, Pppoe, Adsl, Infiniband, OLPCMesh, Bluetooth, Vpn, Vlan, Bridge, Bond, Unknown };
static SortedConnectionType connectionTypeToSortedType(NetworkManager::ConnectionSettings::ConnectionType type);
explicit EditorProxyModel(QObject* parent = 0);
virtual ~EditorProxyModel();
QByteArray sortRole() const;
void setSortRole(const QByteArray& role);
void setSortOrder(Qt::SortOrder order);
QString filterString() const;
void setFilterString(const QString& filter);
Q_INVOKABLE QVariant get(int row, const QString& role);
protected:
int roleKey(const QByteArray &role) const;
QHash<int, QByteArray> roleNames() const;
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
};
......
......@@ -23,6 +23,8 @@
#include "networkmodelitem.h"
#include "uiutils.h"
#include <KLocalizedString>
#if WITH_MODEMMANAGER_SUPPORT
#include <ModemManagerQt/manager.h>
#include <ModemManagerQt/modem.h>
......@@ -47,8 +49,15 @@ QVariant NetworkModel::data(const QModelIndex& index, int role) const
if (row >= 0 && row < m_list.count()) {
NetworkModelItem * item = m_list.itemAt(row);
QStringList editorData;
QStringList editorSection;
switch (role) {
case AppletSectionRole:
if (item->connectionState() == NetworkManager::ActiveConnection::Activated) {
return i18n("Active connections");
} else {
return i18n("Available connections");
}
case ConnectionDetailsRole:
return item->details();
case ConnectionIconRole:
......@@ -79,8 +88,6 @@ QVariant NetworkModel::data(const QModelIndex& index, int role) const
return UiUtils::formatDateRelative(item->timestamp());
case NameRole:
return item->name();
case SectionRole:
return item->sectionType();
case SignalRole:
return item->signal();
case SlaveRole:
......@@ -97,6 +104,10 @@ QVariant NetworkModel::data(const QModelIndex& index, int role) const
return item->timestamp();
case TypeRole:
return item->type();
case TypeStringRole:
return UiUtils::titleForConnectionSettingsType(item->type());
case TypeIconRole:
return UiUtils::iconForConnectionSettingsType(item->type());
case UniRole:
return item->uni();
case UploadRole:
......@@ -122,6 +133,7 @@ int NetworkModel::rowCount(const QModelIndex& parent) const
QHash< int, QByteArray > NetworkModel::roleNames() const
{
QHash<int, QByteArray> roles = QAbstractListModel::roleNames();
roles[AppletSectionRole] = "AppletSection";
roles[ConnectionDetailsRole] = "ConnectionDetails";
roles[ConnectionIconRole] = "ConnectionIcon";
roles[ConnectionPathRole] = "ConnectionPath";
......@@ -135,7 +147,6 @@ QHash< int, QByteArray > NetworkModel::roleNames() const
roles[LastUsedRole] = "LastUsed";
roles[LastUsedDateOnlyRole] = "LastUsedDateOnly";
roles[NameRole] = "Name";
roles[SectionRole] = "Section";
roles[SignalRole] = "Signal";
roles[SlaveRole] = "Slave";
roles[SsidRole] = "Ssid";
......@@ -144,6 +155,8 @@ QHash< int, QByteArray > NetworkModel::roleNames() const
roles[SecurityTypeStringRole] = "SecurityTypeString";
roles[TimeStampRole] = "TimeStamp";
roles[TypeRole] = "Type";
roles[TypeStringRole] = "TypeString";
roles[TypeIconRole] = "TypeIcon";
roles[UniRole] = "Uni";
roles[UploadRole] = "Upload";
roles[UuidRole] = "Uuid";
......
......@@ -44,7 +44,8 @@ public:
virtual ~NetworkModel();
enum ItemRole {
ConnectionDetailsRole = Qt::UserRole + 1,
AppletSectionRole = Qt::UserRole + 1,
ConnectionDetailsRole,
ConnectionIconRole,
ConnectionPathRole,
ConnectionStateRole,
......@@ -59,13 +60,14 @@ public:
NameRole,
SecurityTypeRole,
SecurityTypeStringRole,
SectionRole,
SignalRole,
SlaveRole,
SsidRole,
SpecificPathRole,
TimeStampRole,
TypeRole,
TypeIconRole,
TypeStringRole,
UniRole,
UuidRole,
UploadRole,
......
......@@ -281,15 +281,6 @@ QString NetworkModelItem::originalName() const
return m_name + " (" + m_deviceName + ')';
}
QString NetworkModelItem::sectionType() const
{
if (m_connectionState == NetworkManager::ActiveConnection::Activated) {
return i18n("Active connections");
} else {
return i18n("Available connections");
}
}
NetworkManager::Utils::WirelessSecurityType NetworkModelItem::securityType() const
{
return m_securityType;
......
......@@ -78,8 +78,6 @@ public:
QString originalName() const;
QString sectionType() const;
NetworkManager::Utils::WirelessSecurityType securityType() const;
void setSecurityType(NetworkManager::Utils::WirelessSecurityType type);
......
......@@ -170,22 +170,18 @@ QString UiUtils::iconName(const NetworkManager::Device::Ptr &device)
}
#endif
QString UiUtils::iconAndTitleForConnectionSettingsType(NetworkManager::ConnectionSettings::ConnectionType type, QString &title)
QString UiUtils::titleForConnectionSettingsType(NetworkManager::ConnectionSettings::ConnectionType type)
{
QString text;
QString icon;
switch (type) {
case ConnectionSettings::Adsl:
text = i18n("ADSL");
icon = "modem";
break;
case ConnectionSettings::Pppoe:
text = i18n("DSL");
icon = "modem";
break;
case ConnectionSettings::Bluetooth:
text = i18n("Bluetooth");
icon = "preferences-system-bluetooth";
break;
case ConnectionSettings::Bond:
text = i18n("Bond");
......@@ -196,7 +192,6 @@ QString UiUtils::iconAndTitleForConnectionSettingsType(NetworkManager::Connectio
case ConnectionSettings::Gsm:
case ConnectionSettings::Cdma:
text = i18n("Mobile broadband");
icon = "phone";
break;
case ConnectionSettings::Infiniband:
text = i18n("Infiniband");
......@@ -209,19 +204,15 @@ QString UiUtils::iconAndTitleForConnectionSettingsType(NetworkManager::Connectio
break;
case ConnectionSettings::Vpn:
text = i18n("VPN");
icon = "secure-card";
break;
case ConnectionSettings::Wimax:
text = i18n("WiMAX");
icon = "network-wireless";
break;
case ConnectionSettings::Wired:
text = i18n("Wired");
icon = "network-wired";
break;
case ConnectionSettings::Wireless:
text = i18n("Wireless");
icon = "network-wireless";