File indexing completed on 2024-05-19 16:31:57
0001 /* 0002 * SPDX-FileCopyrightText: 2009 David Hubner <hubnerd@ntlworld.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 * 0006 */ 0007 0008 #include "infopanel.h" 0009 0010 // Solid 0011 #include <solid/device.h> 0012 0013 #include <QIcon> 0014 #include <QLabel> 0015 0016 #include "devinfo.h" 0017 #include "qvlistlayout.h" 0018 0019 InfoPanel::InfoPanel(QWidget *parent, DevInfoPlugin *stat) 0020 : QGroupBox(i18n("Device Information"), parent) 0021 , status(stat) 0022 { 0023 setMinimumWidth(300); 0024 0025 setInfoPanelLayout(); 0026 setDefaultText(); 0027 adjustSize(); 0028 0029 setWhatsThis(i18nc("Info Panel Whats This", "Shows information about the currently selected device.")); 0030 } 0031 0032 InfoPanel::~InfoPanel() 0033 { 0034 delete top; 0035 delete bottom; 0036 } 0037 0038 void InfoPanel::setInfoPanelLayout() 0039 { 0040 vLayout = setAlignedLayout(this); 0041 setLayout(vLayout); 0042 setTopWidgetLayout(true); 0043 0044 setBottomWidgetLayout(new QVListLayout(), true); 0045 } 0046 0047 void InfoPanel::setDefaultText() 0048 { 0049 QLabel *defaultText = new QLabel(); 0050 QFont font; 0051 0052 font.setBold(true); 0053 0054 defaultText->setAlignment(Qt::AlignHCenter); 0055 defaultText->setFont(font); 0056 defaultText->setText(i18n("\nSolid Based Device Viewer Module")); 0057 0058 QVBoxLayout *lay = static_cast<QVBoxLayout *>(top->layout()); 0059 0060 lay->addWidget(setDevicesIcon(QIcon::fromTheme(QStringLiteral("kde"))), 0, Qt::AlignHCenter); 0061 lay->addWidget(defaultText, 0, Qt::AlignHCenter); 0062 } 0063 0064 void InfoPanel::setTopWidgetLayout(bool isInit) 0065 { 0066 if (!isInit) { 0067 delete top; 0068 } 0069 top = new QWidget(this); 0070 0071 vLayout->addWidget(top); 0072 top->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); 0073 top->setLayout(setAlignedLayout(top)); 0074 } 0075 0076 QVBoxLayout *InfoPanel::setAlignedLayout(QWidget *parent, int spacingHeight) 0077 { 0078 QVBoxLayout *lay = new QVBoxLayout(parent); 0079 lay->insertSpacing(0, spacingHeight); 0080 lay->setAlignment(Qt::AlignTop); 0081 0082 return lay; 0083 } 0084 0085 void InfoPanel::setBottomWidgetLayout(QVListLayout *lay, bool isInit) 0086 { 0087 if (!isInit) { 0088 delete bottom; 0089 } 0090 0091 bottom = new QWidget(this); 0092 vLayout->addWidget(bottom); 0093 0094 bottom->setLayout(lay); 0095 } 0096 0097 void InfoPanel::setBottomInfo(QVListLayout *lay) 0098 { 0099 lay->setAlignment(Qt::AlignTop); 0100 lay->insertSpacing(0, 10); 0101 setBottomWidgetLayout(lay); 0102 } 0103 0104 QLabel *InfoPanel::setDevicesIcon(const QIcon &deviceIcon) 0105 { 0106 QLabel *iconLabel = new QLabel(); 0107 0108 iconLabel->setPixmap(deviceIcon.pixmap(QSize(70, 50))); 0109 return iconLabel; 0110 } 0111 0112 void InfoPanel::setTopInfo(const QIcon &deviceIcon, Solid::Device *device) 0113 { 0114 setTopWidgetLayout(); 0115 QVListLayout *tLayout = static_cast<QVListLayout *>(top->layout()); 0116 0117 tLayout->addWidget(setDevicesIcon(deviceIcon), 0, Qt::AlignHCenter); 0118 0119 const QStringList labels{i18n("Description: "), 0120 device->description(), 0121 i18n("Product: "), 0122 device->product(), 0123 i18n("Vendor: "), 0124 friendlyString(device->vendor())}; 0125 0126 status->updateStatus(device->udi()); 0127 tLayout->applyQListToLayout(labels); 0128 } 0129 0130 QString InfoPanel::friendlyString(const QString &input, const QString &blankName) 0131 { 0132 if (input.isEmpty()) { 0133 return QString(blankName); 0134 } 0135 if (input.length() >= 40) { 0136 return input.left(39); 0137 } 0138 0139 return input; 0140 } 0141 0142 QString InfoPanel::convertTf(bool b) 0143 { 0144 if (b) { 0145 return i18n("Yes"); 0146 } 0147 return i18n("No"); 0148 }