Skip to content

Commit

Permalink
openmv: Cleanup object complexity.
Browse files Browse the repository at this point in the history
  • Loading branch information
kwagyeman committed Nov 22, 2024
1 parent d6b2a09 commit 3b3c4c9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/plugins/openmv/openmvplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2445,7 +2445,7 @@ bool OpenMVPlugin::delayedInitialize()
}
});

connect(scanDrivesThread, &ScanDriveThread::driveScanned, this, [this] (const QList<QPair<QStorageInfo, QString> > &output) {
connect(scanDrivesThread, &ScanDriveThread::driveScanned, this, [this] (const QList<QPair<QString, QString> > &output) {
m_availableDrives = output;
});

Expand Down Expand Up @@ -3957,18 +3957,18 @@ void OpenMVPlugin::setPortPath(bool silent)
{
QStringList drives;

for(const QPair<QStorageInfo, QString> &pair : m_availableDrives)
for(const QPair<QString, QString> &pair : m_availableDrives)
{
const QStorageInfo info = pair.first;
const QString rootPath = pair.first;
const QString serialNumber = pair.second;

if((((m_major < OPENMV_DISK_ADDED_MAJOR)
|| ((m_major == OPENMV_DISK_ADDED_MAJOR) && (m_minor < OPENMV_DISK_ADDED_MINOR))
|| ((m_major == OPENMV_DISK_ADDED_MAJOR) && (m_minor == OPENMV_DISK_ADDED_MINOR) && (m_patch < OPENMV_DISK_ADDED_PATCH)))
|| QFile::exists(info.rootPath() + QStringLiteral(OPENMV_DISK_ADDED_NAME)))
|| QFile::exists(rootPath + QStringLiteral(OPENMV_DISK_ADDED_NAME)))
&& (serialNumber.toLower() == m_portDriveSerialNumber.toLower()))
{
drives.append(info.rootPath());
drives.append(rootPath);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/plugins/openmv/openmvplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class ScanDriveThread: public QObject
public: explicit ScanDriveThread() {
}
public slots: void scanDrivesSlot() {
QList<QPair<QStorageInfo, QString> > drives;
QList<QPair<QString, QString> > drives;
for(const QStorageInfo &info : QStorageInfo::mountedVolumes()) {
if(info.isValid()
&& info.isReady()
Expand All @@ -349,12 +349,12 @@ class ScanDriveThread: public QObject
info.rootPath().startsWith(QStringLiteral("/mnt/"), Qt::CaseInsensitive) ||
info.rootPath().startsWith(QStringLiteral("/run/"), Qt::CaseInsensitive)))
{
drives.append(QPair<QStorageInfo, QString>(info, driveSerialNumber(info.rootPath())));
drives.append(QPair<QString, QString>(info.rootPath(), driveSerialNumber(info.rootPath())));
}
}
emit driveScanned(drives);
}
signals: void driveScanned(const QList<QPair<QStorageInfo, QString> > &output);
signals: void driveScanned(const QList<QPair<QString, QString> > &output);
};

class OpenMVPlugin : public ExtensionSystem::IPlugin
Expand Down Expand Up @@ -577,7 +577,7 @@ public slots: // private
QMap<QStringList, QStringList> m_argumentsByHierarchy;
QMap<QStringList, QString> m_returnTypesByHierarchy;
QList<wifiPort_t> m_availableWifiPorts;
QList<QPair<QStorageInfo, QString> > m_availableDrives;
QList<QPair<QString, QString> > m_availableDrives;

typedef struct openTerminalMenuData
{
Expand Down
22 changes: 15 additions & 7 deletions src/plugins/openmv/tools/driveserialnumber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
namespace OpenMV {
namespace Internal {

extern QMutex dfu_util_working;

QString serialPortDriveSerialNumber(const QString &portName)
{
#if defined(Q_OS_WIN)
Expand All @@ -20,7 +22,7 @@ QString serialPortDriveSerialNumber(const QString &portName)
QStringList()
<< QStringLiteral("-Command")
<< QString(QStringLiteral("(Get-PnpDeviceProperty -InstanceId (Get-WmiObject Win32_SerialPort | Where-Object { $_.DeviceID -eq '%1' }).PNPDeviceId | Where-Object { $_.KeyName -eq 'DEVPKEY_Device_Parent' }).Data")).arg(QString(portName))));
process.runBlocking(timeout, Utils::EventLoopMode::On);
process.runBlocking(timeout, Utils::EventLoopMode::Off);

if(process.result() == Utils::ProcessResult::FinishedWithSuccess)
{
Expand All @@ -46,14 +48,16 @@ QString driveSerialNumber(const QString &drivePath)
QStringList()
<< QStringLiteral("-Command")
<< QString(QStringLiteral("(Get-Disk -Number (Get-Partition -DriveLetter '%1').DiskNumber).SerialNumber")).arg(QString(drivePath).remove(QStringLiteral(":")).remove(QStringLiteral("/")))));
process.runBlocking(timeout, Utils::EventLoopMode::On);
process.runBlocking(timeout, Utils::EventLoopMode::Off);

if(process.result() == Utils::ProcessResult::FinishedWithSuccess)
{
QString serialNumber = process.stdOut().trimmed();
return serialNumber;
}
#elif defined(Q_OS_LINUX)
if(!dfu_util_working.try_lock()) return QString();

Utils::Process process;
std::chrono::seconds timeout(10);
process.setTextChannelMode(Utils::Channel::Output, Utils::TextChannelMode::MultiLine);
Expand All @@ -63,13 +67,13 @@ QString driveSerialNumber(const QString &drivePath)
<< QStringLiteral("-J")
<< QStringLiteral("-o")
<< QStringLiteral("MOUNTPOINT,NAME,SERIAL")));
process.runBlocking(timeout, Utils::EventLoopMode::On);
process.runBlocking(timeout, Utils::EventLoopMode::Off);

if(process.result() == Utils::ProcessResult::FinishedWithSuccess)
{
QJsonDocument doc = QJsonDocument::fromJson(process.stdOut().toUtf8());

if (doc.isObject())
if (!doc.isNull())
{
QString cleanDrivePath = QDir::fromNativeSeparators(QDir::cleanPath(drivePath));

Expand All @@ -81,6 +85,7 @@ QString driveSerialNumber(const QString &drivePath)

if (mountPoint == cleanDrivePath)
{
dfu_util_working.unlock();
return serialNumber;
}

Expand All @@ -92,12 +97,15 @@ QString driveSerialNumber(const QString &drivePath)

if (childMountPoint == cleanDrivePath)
{
dfu_util_working.unlock();
return childSerialNumber.isEmpty() ? serialNumber : childSerialNumber;
}
}
}
}
}

dfu_util_working.unlock();
#elif defined(Q_OS_MAC)
Utils::Process process;
std::chrono::seconds timeout(10);
Expand All @@ -106,13 +114,13 @@ QString driveSerialNumber(const QString &drivePath)
process.setCommand(Utils::CommandLine(Utils::FilePath::fromString(QStringLiteral("system_profiler")), QStringList()
<< QStringLiteral("SPUSBDataType")
<< QStringLiteral("-json")));
process.runBlocking(timeout, Utils::EventLoopMode::On);
process.runBlocking(timeout, Utils::EventLoopMode::Off);

if(process.result() == Utils::ProcessResult::FinishedWithSuccess)
{
QJsonDocument doc = QJsonDocument::fromJson(process.stdOut().toUtf8());

if (doc.isObject())
if (!doc.isNull())
{
for (const QJsonValue &val : doc.object().value(QStringLiteral("SPUSBDataType")).toArray())
{
Expand All @@ -134,7 +142,7 @@ QString driveSerialNumber(const QString &drivePath)
<< QStringLiteral("list")
<< QStringLiteral("-plist")
<< diskName));
process.runBlocking(timeout, Utils::EventLoopMode::On);
process.runBlocking(timeout, Utils::EventLoopMode::Off);

if (process.stdOut().contains(QString(QStringLiteral("<string>%1</string>")).arg(drivePath)))
{
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/openmv/tools/myqserialportinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ MyQSerialPortInfo::MyQSerialPortInfo(const QSerialPortInfo &info)
<< QStringLiteral("-v")
<< QStringLiteral("-d")
<< QString(QStringLiteral("%1:%2")).arg(m_vendorIdentifier, 4, 16, QLatin1Char('0')).arg(m_productIdentifier, 4, 16, QLatin1Char('0'))));
process.runBlocking(timeout, Utils::EventLoopMode::On);
process.runBlocking(timeout, Utils::EventLoopMode::Off);

if(process.result() == Utils::ProcessResult::FinishedWithSuccess)
{
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/tabbededitor/tabbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ void TabBar::activateEditor(int index)

void TabBar::addEditorTab(Core::IEditor *editor)
{
if (!editor) return;
Core::IDocument *document = editor->document();
if (!document) return;

const int index = addTab(document->displayName());
// OPENMV-DIFF //
Expand Down

0 comments on commit 3b3c4c9

Please sign in to comment.