kinfocenter: fix usbview module devices refreshing

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-04-30 16:42:05 +03:00
parent e943322e7d
commit fa2017ccd8
2 changed files with 17 additions and 8 deletions

View file

@ -30,8 +30,10 @@
K_PLUGIN_FACTORY(USBFactory, registerPlugin<USBViewer>();) K_PLUGIN_FACTORY(USBFactory, registerPlugin<USBViewer>();)
K_EXPORT_PLUGIN(USBFactory("kcmusb")) K_EXPORT_PLUGIN(USBFactory("kcmusb"))
USBViewer::USBViewer(QWidget *parent, const QVariantList &) : USBViewer::USBViewer(QWidget *parent, const QVariantList &)
KCModule(USBFactory::componentData(), parent) { : KCModule(USBFactory::componentData(), parent),
_lastdevicecount(0)
{
setQuickHelp(i18n("This module allows you to see the devices attached to your USB bus(es).")); setQuickHelp(i18n("This module allows you to see the devices attached to your USB bus(es)."));
setButtons(KCModule::Help | KCModule::Export); setButtons(KCModule::Help | KCModule::Export);
@ -78,9 +80,6 @@ USBViewer::USBViewer(QWidget *parent, const QVariantList &) :
} }
void USBViewer::load() { void USBViewer::load() {
_items.clear();
_devices->clear();
refresh(); refresh();
} }
@ -108,10 +107,19 @@ static void delete_recursive(QTreeWidgetItem *item, const QMap<int, QTreeWidgetI
} }
} }
void USBViewer::refresh() { void USBViewer::refresh()
QMap<int, QTreeWidgetItem*> new_items; {
USBDevice::init(); USBDevice::init();
const int currentdevicecount = USBDevice::devices().size();
if (currentdevicecount == _lastdevicecount) {
return;
}
_lastdevicecount = currentdevicecount;
_items.clear();
_devices->clear();
QMap<int, QTreeWidgetItem*> new_items;
int level = 0; int level = 0;
bool found = true; bool found = true;

View file

@ -32,6 +32,7 @@ protected Q_SLOTS:
void refresh(); void refresh();
private: private:
int _lastdevicecount;
QMap<int, QTreeWidgetItem*> _items; QMap<int, QTreeWidgetItem*> _items;
QTreeWidget *_devices; QTreeWidget *_devices;
QTextEdit *_details; QTextEdit *_details;