[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdebase/kcontrol/usbview
From: Leo Savernik <l.savernik () aon ! at>
Date: 2004-04-23 12:18:01
Message-ID: 20040423121801.461359A66 () office ! kde ! org
[Download RAW message or body]
CVS commit by savernik:
Fixed bug in usbview to make it update its view on plug-in/removal of
devices while it is running.
M +43 -11 kcmusb.cpp 1.16
M +3 -2 kcmusb.h 1.5
--- kdebase/kcontrol/usbview/kcmusb.cpp #1.15:1.16
@@ -18,4 +18,5 @@
#include <qtextview.h>
#include <qheader.h>
+#include <qtimer.h>
#include <kgenericfactory.h>
@@ -59,4 +60,9 @@ USBViewer::USBViewer(QWidget *parent, co
splitter->setResizeMode(_devices, QSplitter::KeepSize);
+ QTimer *refreshTimer = new QTimer(this);
+ // 1 sec seems to be a good compromise between latency and polling load.
+ refreshTimer->start(1000);
+
+ connect(refreshTimer, SIGNAL(timeout()), SLOT(refresh()));
connect(_devices, SIGNAL(selectionChanged(QListViewItem*)),
this, SLOT(selectionChanged(QListViewItem*)));
@@ -73,8 +79,14 @@ USBViewer::~USBViewer()
void USBViewer::load()
{
- QIntDict<QListViewItem> _items;
-
+ _items.clear();
_devices->clear();
+ refresh();
+}
+
+void USBViewer::refresh()
+{
+ QIntDict<QListViewItem> new_items;
+
USBDevice::parse("/proc/bus/usb/devices");
@@ -92,9 +104,12 @@ void USBViewer::load()
if (level == 0)
{
- QListViewItem *item = new QListViewItem(_devices,
+ QListViewItem *item = _items.find(it.current()->bus()*256+it.current()->device());
+ if (!item) {
+ item = new QListViewItem(_devices,
it.current()->product(),
QString("%1").arg(it.current()->bus()),
QString("%1").arg(it.current()->device()) );
- _items.insert(it.current()->bus()*256+it.current()->device(),
+ }
+ new_items.insert(it.current()->bus()*256+it.current()->device(),
item);
found = true;
@@ -105,9 +120,13 @@ void USBViewer::load()
if (parent)
{
- QListViewItem *item = new QListViewItem(parent,
+ QListViewItem *item = _items.find(it.current()->bus()*256+it.current()->device());
+
+ if (!item) {
+ item = new QListViewItem(parent,
it.current()->product(),
QString("%1").arg(it.current()->bus()),
QString("%1").arg(it.current()->device()) );
- _items.insert(it.current()->bus()*256+it.current()->device(),
+ }
+ new_items.insert(it.current()->bus()*256+it.current()->device(),
item);
parent->setOpen(true);
@@ -120,4 +139,16 @@ void USBViewer::load()
}
+ // delete all items not in new_list
+ {
+ QIntDictIterator<QListViewItem> it(_items);
+ for (; it.current(); ++it) {
+ if (!new_items.find(it.currentKey()))
+ delete it.current();
+ }
+ }
+
+ _items = new_items;
+
+ if (!_devices->selectedItem())
selectionChanged(_devices->firstChild());
}
@@ -164,4 +195,5 @@ const KAboutData* USBViewer::aboutData()
about->addAuthor("Matthias Hoelzer-Kluepfel", 0, "mhk@kde.org");
+ about->addCredit("Leo Savernik", "Live Monitoring of USB Bus", "l.savernik@aon.at");
return about;
--- kdebase/kcontrol/usbview/kcmusb.h #1.4:1.5
@@ -47,8 +47,9 @@ protected slots:
void selectionChanged(QListViewItem *item);
-
+ void refresh();
private:
+ QIntDict<QListViewItem> _items;
QListView *_devices;
QTextView *_details;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic