Commit 11b1773e authored by Laurent Montel's avatar Laurent Montel 😁

Reindent it

parent 891c9788
/*
* devicelisting.cpp
*
......@@ -24,189 +23,201 @@
#include <QMenu>
DeviceListing::DeviceListing(QWidget *parent, InfoPanel *info, DevInfoPlugin *stat) :
QTreeWidget(parent), iPanel(info), status(stat)
{
DeviceListing::DeviceListing(QWidget *parent, InfoPanel *info, DevInfoPlugin *stat)
: QTreeWidget(parent)
, iPanel(info)
, status(stat)
{
// // Check nic changes
// nicSig = new NicSignals();
// connect(nicSig,SIGNAL(nicActivatedOrDisconnected()),this,SLOT(networkingChangedSlot()));
//
// Check if clicked
connect(this, &DeviceListing::itemActivated, this, &DeviceListing::itemActivatedSlot);
// Check if item is added
connect(Solid::DeviceNotifier::instance(),SIGNAL(deviceAdded(QString)),this,SLOT(deviceAddedSlot(QString)));
connect(Solid::DeviceNotifier::instance(), SIGNAL(deviceAdded(QString)), this,
SLOT(deviceAddedSlot(QString)));
// Check if item is removed
connect(Solid::DeviceNotifier::instance(),SIGNAL(deviceRemoved(QString)),this,SLOT(deviceRemovedSlot(QString)));
setWhatsThis(i18nc("Device Listing Whats This","Shows all the devices that are currently listed."));
connect(Solid::DeviceNotifier::instance(), SIGNAL(deviceRemoved(QString)), this,
SLOT(deviceRemovedSlot(QString)));
setWhatsThis(i18nc("Device Listing Whats This",
"Shows all the devices that are currently listed."));
createMenuActions();
setHeaderLabels(QStringList(i18n("Devices")));
populateListing();
populateListing();
}
DeviceListing::~DeviceListing()
{
//delete nicSig;
clear();
{
//delete nicSig;
clear();
}
void DeviceListing::createMenuActions()
{
colAct = new QAction(i18n("Collapse All"), this);
connect(colAct, &QAction::triggered, this, &DeviceListing::collapseAllDevicesSlot);
expAct = new QAction(i18n("Expand All"), this);
connect(expAct, &QAction::triggered, this, &DeviceListing::expandAllDevicesSlot);
allAct = new QAction(i18n("Show All Devices"), this);
connect(allAct, &QAction::triggered, this, &DeviceListing::showAllDevicesSlot);
relAct = new QAction(i18n("Show Relevant Devices"), this);
connect(relAct, &QAction::triggered, this, &DeviceListing::showRelevantDevicesSlot);
void DeviceListing::createMenuActions()
{
colAct = new QAction(i18n("Collapse All"), this);
connect(colAct, &QAction::triggered, this, &DeviceListing::collapseAllDevicesSlot);
expAct = new QAction(i18n("Expand All"), this);
connect(expAct, &QAction::triggered, this, &DeviceListing::expandAllDevicesSlot);
allAct = new QAction(i18n("Show All Devices"), this);
connect(allAct, &QAction::triggered, this, &DeviceListing::showAllDevicesSlot);
relAct = new QAction(i18n("Show Relevant Devices"), this);
connect(relAct, &QAction::triggered, this, &DeviceListing::showRelevantDevicesSlot);
}
void DeviceListing::contextMenuEvent(QContextMenuEvent *event)
{
QMenu menu(this);
menu.addAction(colAct);
menu.addAction(expAct);
menu.addAction(allAct);
menu.addAction(relAct);
menu.exec(event->globalPos());
void DeviceListing::contextMenuEvent(QContextMenuEvent *event)
{
QMenu menu(this);
menu.addAction(colAct);
menu.addAction(expAct);
menu.addAction(allAct);
menu.addAction(relAct);
menu.exec(event->globalPos());
}
QTreeWidgetItem *DeviceListing::createListItems(const Solid::DeviceInterface::Type &type)
QTreeWidgetItem *DeviceListing::createListItems(const Solid::DeviceInterface::Type &type)
{
switch(type)
{
case Solid::DeviceInterface::Processor:
return new SolProcessorDevice(type);
case Solid::DeviceInterface::StorageDrive:
return new SolStorageDevice(type);
case Solid::DeviceInterface::Camera:
return new SolCameraDevice(type);
case Solid::DeviceInterface::PortableMediaPlayer:
return new SolMediaPlayerDevice(type);
case Solid::DeviceInterface::Battery:
return new SolBatteryDevice(type);
default:
return new SolDevice(type,i18nc("unknown device type", "Unknown"));
}
switch (type) {
case Solid::DeviceInterface::Processor:
return new SolProcessorDevice(type);
case Solid::DeviceInterface::StorageDrive:
return new SolStorageDevice(type);
case Solid::DeviceInterface::Camera:
return new SolCameraDevice(type);
case Solid::DeviceInterface::PortableMediaPlayer:
return new SolMediaPlayerDevice(type);
case Solid::DeviceInterface::Battery:
return new SolBatteryDevice(type);
default:
return new SolDevice(type, i18nc("unknown device type", "Unknown"));
}
}
void DeviceListing::populateListing(const show showStatus)
{
const Solid::DeviceInterface::Type needHardware[] = {
Solid::DeviceInterface::Processor,
Solid::DeviceInterface::StorageDrive,
Solid::DeviceInterface::Battery,
Solid::DeviceInterface::PortableMediaPlayer,
Solid::DeviceInterface::Camera
};
clear();
for(unsigned int i=0;i<(sizeof(needHardware)/sizeof(Solid::DeviceInterface::Type));i++)
{
QTreeWidgetItem *tmpDevice = createListItems(needHardware[i]);
deviceMap[needHardware[i]] = static_cast<SolDevice *>(tmpDevice);
if((tmpDevice->childCount() > 0) || (showStatus==ALL))
{
addTopLevelItem(tmpDevice);
}
}
{
const Solid::DeviceInterface::Type needHardware[] = {
Solid::DeviceInterface::Processor,
Solid::DeviceInterface::StorageDrive,
Solid::DeviceInterface::Battery,
Solid::DeviceInterface::PortableMediaPlayer,
Solid::DeviceInterface::Camera
};
clear();
for (unsigned int i = 0; i < (sizeof(needHardware)/sizeof(Solid::DeviceInterface::Type)); i++) {
QTreeWidgetItem *tmpDevice = createListItems(needHardware[i]);
deviceMap[needHardware[i]] = static_cast<SolDevice *>(tmpDevice);
if ((tmpDevice->childCount() > 0) || (showStatus == ALL)) {
addTopLevelItem(tmpDevice);
}
}
}
void DeviceListing::itemActivatedSlot(QTreeWidgetItem *listItemIn ,const int columnIn)
void DeviceListing::itemActivatedSlot(QTreeWidgetItem *listItemIn, const int columnIn)
{
Q_UNUSED(columnIn);
SolDevice *listItem = static_cast<SolDevice *>(listItemIn);
if(listItem->isDeviceSet())
{
iPanel->setTopInfo(listItem->deviceIcon(),listItem->device());
QVListLayout *bottomLay = listItem->infoPanelLayout();
if(!bottomLay) return;
iPanel->setBottomInfo(bottomLay);
} else {
status->updateStatus(i18nc("no device UDI", "None"));
}
Q_UNUSED(columnIn);
SolDevice *listItem = static_cast<SolDevice *>(listItemIn);
if (listItem->isDeviceSet()) {
iPanel->setTopInfo(listItem->deviceIcon(), listItem->device());
QVListLayout *bottomLay = listItem->infoPanelLayout();
if (!bottomLay) {
return;
}
iPanel->setBottomInfo(bottomLay);
} else {
status->updateStatus(i18nc("no device UDI", "None"));
}
}
void DeviceListing::deviceAddedSlot(const QString &udi)
{
SolidHelper *solhelp = new SolidHelper();
const QList<Solid::Device> list = Solid::Device::allDevices();
foreach(const Solid::Device &dev, list)
{
if(dev.udi() == udi)
{
Solid::DeviceInterface::Type deviceType = solhelp->deviceType(&dev);
QTreeWidgetItem *parent = getTreeWidgetItemFromUdi(this,dev.parentUdi());
// Incase of bad index
if(deviceMap[deviceType] == NULL)
{
QTreeWidgetItem *topItem = topLevelItem(0);
if(topItem == 0) { delete solhelp; return; }
deviceMap[deviceType] = static_cast<SolDevice *>(topItem);
}
switch(deviceType)
{
case Solid::DeviceInterface::Processor:
new SolProcessorDevice(deviceMap[deviceType],dev); break;
case Solid::DeviceInterface::Camera:
new SolCameraDevice(deviceMap[deviceType],dev); break;
case Solid::DeviceInterface::PortableMediaPlayer:
new SolMediaPlayerDevice(deviceMap[deviceType],dev); break;
case Solid::DeviceInterface::Battery:
new SolBatteryDevice(deviceMap[deviceType],dev); break;
case Solid::DeviceInterface::StorageDrive:
new SolStorageDevice(deviceMap[deviceType],dev,SolStorageDevice::NOCHILDREN); break;
case Solid::DeviceInterface::StorageVolume:
if(parent == NULL) break;
new SolVolumeDevice(parent,dev); break;
default:
break;
}
{
SolidHelper *solhelp = new SolidHelper();
const QList<Solid::Device> list = Solid::Device::allDevices();
foreach (const Solid::Device &dev, list) {
if (dev.udi() == udi) {
Solid::DeviceInterface::Type deviceType = solhelp->deviceType(&dev);
QTreeWidgetItem *parent = getTreeWidgetItemFromUdi(this, dev.parentUdi());
// Incase of bad index
if (deviceMap[deviceType] == NULL) {
QTreeWidgetItem *topItem = topLevelItem(0);
if (topItem == 0) {
delete solhelp;
return;
}
deviceMap[deviceType] = static_cast<SolDevice *>(topItem);
}
switch (deviceType) {
case Solid::DeviceInterface::Processor:
new SolProcessorDevice(deviceMap[deviceType], dev);
break;
case Solid::DeviceInterface::Camera:
new SolCameraDevice(deviceMap[deviceType], dev);
break;
case Solid::DeviceInterface::PortableMediaPlayer:
new SolMediaPlayerDevice(deviceMap[deviceType], dev);
break;
case Solid::DeviceInterface::Battery:
new SolBatteryDevice(deviceMap[deviceType], dev);
break;
case Solid::DeviceInterface::StorageDrive:
new SolStorageDevice(deviceMap[deviceType], dev, SolStorageDevice::NOCHILDREN);
break;
case Solid::DeviceInterface::StorageVolume:
if (parent == NULL) {
break;
}
new SolVolumeDevice(parent, dev);
break;
default:
break;
}
}
}
}
delete solhelp;
delete solhelp;
}
void DeviceListing::deviceRemovedSlot(const QString &udi)
{
const QTreeWidgetItem *item = getTreeWidgetItemFromUdi(this,udi);
if(item == nullptr) return;
delete item;
const QTreeWidgetItem *item = getTreeWidgetItemFromUdi(this, udi);
if (item == nullptr) {
return;
}
delete item;
}
void DeviceListing::collapseAllDevicesSlot()
{
collapseAll();
void DeviceListing::collapseAllDevicesSlot()
{
collapseAll();
}
void DeviceListing::expandAllDevicesSlot()
{
expandAll();
void DeviceListing::expandAllDevicesSlot()
{
expandAll();
}
void DeviceListing::showAllDevicesSlot()
{
populateListing(ALL);
void DeviceListing::showAllDevicesSlot()
{
populateListing(ALL);
}
void DeviceListing::showRelevantDevicesSlot()
{
populateListing(RELEVANT);
void DeviceListing::showRelevantDevicesSlot()
{
populateListing(RELEVANT);
}
/*
* devicelisting.h
*
......@@ -29,7 +28,7 @@
#include <solid/processor.h>
#include <solid/devicenotifier.h>
//QT
//QT
#include <QMap>
#include <QTreeWidget>
#include <QAction>
......@@ -51,42 +50,46 @@ class DevInfoPlugin;
//class NicSignals;
class DeviceListing : public QTreeWidget
{
Q_OBJECT
{
Q_OBJECT
private:
enum show { ALL=0, RELEVANT };
private:
enum show {
ALL = 0, RELEVANT
};
public:
public:
DeviceListing(QWidget *, InfoPanel *, DevInfoPlugin *);
~DeviceListing();
~DeviceListing();
static QTreeWidgetItem *getTreeWidgetItemFromUdi(QTreeWidget *widget, const QString &udi)
{
QTreeWidgetItemIterator treeWidget(widget);
while (*treeWidget)
{
SolDevice *item = static_cast<SolDevice *>(*treeWidget);
if(item->udi() == udi) return *treeWidget;
++treeWidget;
}
return NULL;
while (*treeWidget)
{
SolDevice *item = static_cast<SolDevice *>(*treeWidget);
if (item->udi() == udi) {
return *treeWidget;
}
++treeWidget;
}
return NULL;
}
private:
void populateListing(const show=RELEVANT);
private:
void populateListing(const show = RELEVANT);
QTreeWidgetItem *createListItems(const Solid::DeviceInterface::Type &);
void contextMenuEvent(QContextMenuEvent *) Q_DECL_OVERRIDE;
void createMenuActions();
QMap<Solid::DeviceInterface::Type, SolDevice *> deviceMap;
InfoPanel *iPanel;
QAction *colAct, *expAct, *allAct, *relAct;
DevInfoPlugin *status;
//NicSignals *nicSig;
public Q_SLOTS:
void itemActivatedSlot(QTreeWidgetItem *,const int);
public Q_SLOTS:
void itemActivatedSlot(QTreeWidgetItem *, const int);
void deviceAddedSlot(const QString &);
void deviceRemovedSlot(const QString &);
void collapseAllDevicesSlot();
......
/*
* devinfo.cpp
*
......@@ -24,77 +23,78 @@
#include <QSplitter>
#include <KLocalizedString>
K_PLUGIN_FACTORY(devInfoModuleFactory, registerPlugin<DevInfoPlugin>();)
K_PLUGIN_FACTORY(devInfoModuleFactory, registerPlugin<DevInfoPlugin>();
)
DevInfoPlugin::DevInfoPlugin(QWidget *parent, const QVariantList &) :
KCModule(parent)
DevInfoPlugin::DevInfoPlugin(QWidget *parent, const QVariantList &)
: KCModule(parent)
{
const KAboutData *about =
new KAboutData(i18n("kcmdevinfo"), i18n("Device Viewer"),
QStringLiteral("0.70"), QString(), KAboutLicense::GPL,
i18n("(c) 2010 David Hubner"));
setAboutData(about);
//Layout
layout = new QGridLayout(this);
layout->setContentsMargins(0,0,0,0);
//top
QSplitter *split = new QSplitter(Qt::Horizontal, this);
split->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
split->setChildrenCollapsible(false);
InfoPanel *info = new InfoPanel(split, this);
DeviceListing *devList = new DeviceListing(split, info, this);
split->setStretchFactor(1,1);
//bottom
QWidget *bottom = new QWidget(this);
bottom->setContentsMargins(0,0,0,0);
bottom->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum);
QHBoxLayout *bottomLayout = new QHBoxLayout(bottom);
bottomLayout->setContentsMargins(0,0,0,0);
QFont boldFont;
boldFont.setBold(true);
QLabel *udiLabel = new QLabel(i18n("UDI: "));
udiLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
udiLabel->setFont(boldFont);
udiLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
udiStatus = new QLabel(this);
udiStatus->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
udiStatus->setTextInteractionFlags(Qt::TextSelectableByMouse);
udiStatus->setWhatsThis(i18nc("Udi Whats This","Shows the current device's UDI (Unique Device Identifier)"));
//Adding
split->addWidget(devList);
split->addWidget(info);
layout->addWidget(split,0,0);
bottomLayout->addWidget(udiLabel);
bottomLayout->addWidget(udiStatus);
layout->addWidget(bottom,1,0,1,0);
//Misc
setButtons(Help);
updateStatus(i18nc("no device UDI", "None"));
const KAboutData *about
= new KAboutData(i18n("kcmdevinfo"), i18n("Device Viewer"),
QStringLiteral("0.70"), QString(), KAboutLicense::GPL,
i18n("(c) 2010 David Hubner"));
setAboutData(about);
//Layout
layout = new QGridLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
//top
QSplitter *split = new QSplitter(Qt::Horizontal, this);
split->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
split->setChildrenCollapsible(false);
InfoPanel *info = new InfoPanel(split, this);
DeviceListing *devList = new DeviceListing(split, info, this);
split->setStretchFactor(1, 1);
//bottom
QWidget *bottom = new QWidget(this);
bottom->setContentsMargins(0, 0, 0, 0);
bottom->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum);
QHBoxLayout *bottomLayout = new QHBoxLayout(bottom);
bottomLayout->setContentsMargins(0, 0, 0, 0);
QFont boldFont;
boldFont.setBold(true);
QLabel *udiLabel = new QLabel(i18n("UDI: "));
udiLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
udiLabel->setFont(boldFont);
udiLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
udiStatus = new QLabel(this);
udiStatus->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
udiStatus->setTextInteractionFlags(Qt::TextSelectableByMouse);
udiStatus->setWhatsThis(i18nc("Udi Whats This",
"Shows the current device's UDI (Unique Device Identifier)"));
//Adding
split->addWidget(devList);
split->addWidget(info);
layout->addWidget(split, 0, 0);
bottomLayout->addWidget(udiLabel);
bottomLayout->addWidget(udiStatus);
layout->addWidget(bottom, 1, 0, 1, 0);
//Misc
setButtons(Help);
updateStatus(i18nc("no device UDI", "None"));
}
DevInfoPlugin::~DevInfoPlugin()
{
delete layout;
DevInfoPlugin::~DevInfoPlugin()
{
delete layout;
}
void DevInfoPlugin::updateStatus(const QString &message)
{
udiStatus->setText(message);
{
udiStatus->setText(message);
}
#include "devinfo.moc"
/*
* devinfo.h
*
......@@ -37,18 +36,17 @@
#include "devicelisting.h"
#include "infopanel.h"
class DevInfoPlugin : public KCModule
{
Q_OBJECT
public:
Q_OBJECT