summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXizhi Zhu <xizhi.zhu@nokia.com>2012-03-02 19:38:59 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-05 15:28:34 +0100
commit0c2d461258e81439e4737157315ac7d16e0f609f (patch)
treec797cc56c0a820669145bb2cd5a2d3ebe60e785e
parent35b937e817dadc27aa7b132505498b2b19ddbb06 (diff)
Refactor the storage info on Linux.
Move the logic to handle UDev to setup / cleanup wrapper. Change-Id: I41442afcbcb67f1d958b598a2e868956b5373976 Reviewed-by: Steffen Hahn <steffen.hahn@nokia.com> Reviewed-by: Xizhi Zhu <xizhi.zhu@nokia.com>
-rw-r--r--src/systeminfo/qstorageinfo_linux.cpp62
-rw-r--r--src/systeminfo/qstorageinfo_linux_p.h4
2 files changed, 28 insertions, 38 deletions
diff --git a/src/systeminfo/qstorageinfo_linux.cpp b/src/systeminfo/qstorageinfo_linux.cpp
index 6db9d30f..ce509590 100644
--- a/src/systeminfo/qstorageinfo_linux.cpp
+++ b/src/systeminfo/qstorageinfo_linux.cpp
@@ -87,7 +87,7 @@ QStorageInfoPrivate::QStorageInfoPrivate(QStorageInfo *parent)
, notifier(0)
#if !defined(QT_NO_UDEV)
, udevWrapper(0)
- , udevWatcher(false)
+ , needsUDevWatcher(-1)
#endif // QT_NO_UDEV
{
}
@@ -169,7 +169,7 @@ QStringList QStorageInfoPrivate::allLogicalDrives()
{
// No need to update the list if someone is listening to the signal, as it will be updated in that case
#if !defined(QT_NO_UDEV)
- if (inotifyWatcher == -1 && !udevWatcher)
+ if (inotifyWatcher == -1 && needsUDevWatcher != 2)
#else
if (inotifyWatcher == -1)
#endif // QT_NO_UDEV
@@ -262,51 +262,28 @@ QStorageInfo::DriveType QStorageInfoPrivate::driveType(const QString &drive)
void QStorageInfoPrivate::connectNotify(const char *signal)
{
if (strcmp(signal, SIGNAL(logicalDriveChanged(QString,bool))) == 0) {
-#if !defined(QT_NO_UDEV)
- if (!udevWatcher) {
- if (QFileInfo(QStringLiteral("/etc/mtab")).isSymLink())
- udevWatcher = true;
- else
- udevWatcher = false;
- }
-#endif // QT_NO_UDEV
-
updateLogicalDrives();
-
-#if !defined(QT_NO_UDEV)
- if (!udevWatcher) {
- setupWatcher();
- } else {
- if (!udevWrapper)
- udevWrapper = new QUDevWrapper(this);
- connect(udevWrapper, SIGNAL(driveChanged()), this, SLOT(onDriveChanged()));
- }
-#else
setupWatcher();
-#endif // QT_NO_UDEV
}
}
void QStorageInfoPrivate::disconnectNotify(const char *signal)
{
- if (strcmp(signal, SIGNAL(logicalDriveChanged(QString,bool))) == 0) {
-#if !defined(QT_NO_UDEV)
- if (!udevWatcher) {
- cleanupWatcher();
- } else {
- if (!udevWrapper)
- udevWrapper = new QUDevWrapper(this);
- disconnect(udevWrapper, SIGNAL(driveChanged()), this, SLOT(onDriveChanged()));
- udevWatcher = 0;
- }
-#else
+ if (strcmp(signal, SIGNAL(logicalDriveChanged(QString,bool))) == 0)
cleanupWatcher();
-#endif // QT_NO_UDEV
- }
}
void QStorageInfoPrivate::cleanupWatcher()
{
+#if !defined(QT_NO_UDEV)
+ if (needsUDevWatcher == 2) {
+ needsUDevWatcher = 1;
+ if (udevWrapper)
+ disconnect(udevWrapper, SIGNAL(driveChanged()), this, SLOT(onDriveChanged()));
+ return;
+ }
+#endif // QT_NO_UDEV
+
if (notifier) {
delete notifier;
notifier = 0;
@@ -325,6 +302,19 @@ void QStorageInfoPrivate::cleanupWatcher()
void QStorageInfoPrivate::setupWatcher()
{
+#if !defined(QT_NO_UDEV)
+ if (needsUDevWatcher == -1)
+ needsUDevWatcher = QFileInfo(QStringLiteral("/etc/mtab")).isSymLink();
+
+ if (needsUDevWatcher == 1) {
+ if (!udevWrapper)
+ udevWrapper = new QUDevWrapper(this);
+ connect(udevWrapper, SIGNAL(driveChanged()), this, SLOT(onDriveChanged()));
+ needsUDevWatcher = 2;
+ return;
+ }
+#endif // QT_NO_UDEV
+
if (inotifyFileDescriptor == -1
&& (inotifyFileDescriptor = inotify_init()) == -1) {
return;
@@ -379,7 +369,6 @@ void QStorageInfoPrivate::onInotifyActivated()
}
#if !defined(QT_NO_UDEV)
-
void QStorageInfoPrivate::onDriveChanged()
{
QStringList oldLogicalDrives = logicalDrives;
@@ -395,7 +384,6 @@ void QStorageInfoPrivate::onDriveChanged()
emit logicalDriveChanged(drive, true);
}
}
-
#endif // QT_NO_UDEV
QT_END_NAMESPACE
diff --git a/src/systeminfo/qstorageinfo_linux_p.h b/src/systeminfo/qstorageinfo_linux_p.h
index c2bce732..8b3c2134 100644
--- a/src/systeminfo/qstorageinfo_linux_p.h
+++ b/src/systeminfo/qstorageinfo_linux_p.h
@@ -94,7 +94,9 @@ private:
QStringList logicalDrives;
#if !defined(QT_NO_UDEV)
QUDevWrapper *udevWrapper;
- bool udevWatcher;
+ int needsUDevWatcher; // -1: unknown; 0: no need;
+ // 1: needed, but not currently watching;
+ // 2: needed and currently watching
#endif // QT_NO_UDEV
void cleanupWatcher();