1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

Uncrustify

This commit is contained in:
Oleg Semyonov 2013-06-03 19:13:11 +02:00
parent b5b48d3bf0
commit 1cfc7f1586
6 changed files with 138 additions and 145 deletions

View File

@ -43,54 +43,51 @@ using namespace Core;
using namespace Core::Internal;
namespace {
struct PageData {
int index;
QString category;
QString id;
};
struct PageData {
int index;
QString category;
QString id;
// helper to sort by translated category and name
bool compareOptionsPageByCategoryAndNameTr(const IOptionsPage *p1, const IOptionsPage *p2)
{
const UAVGadgetOptionsPageDecorator *gp1 = qobject_cast<const UAVGadgetOptionsPageDecorator *>(p1);
const UAVGadgetOptionsPageDecorator *gp2 = qobject_cast<const UAVGadgetOptionsPageDecorator *>(p2);
};
// helper to sort by translated category and name
bool compareOptionsPageByCategoryAndNameTr(const IOptionsPage *p1, const IOptionsPage *p2)
{
const UAVGadgetOptionsPageDecorator *gp1 = qobject_cast<const UAVGadgetOptionsPageDecorator *>(p1);
const UAVGadgetOptionsPageDecorator *gp2 = qobject_cast<const UAVGadgetOptionsPageDecorator *>(p2);
if (gp1 && !gp2) {
return false;
}
if (gp2 && !gp1) {
return true;
}
if (const int cc = QString::localeAwareCompare(p1->trCategory(), p2->trCategory())) {
return cc < 0;
}
return QString::localeAwareCompare(p1->trName(), p2->trName()) < 0;
if (gp1 && !gp2) {
return false;
}
// helper to sort by category and id
bool compareOptionsPageByCategoryAndId(const IOptionsPage *p1, const IOptionsPage *p2)
{
const UAVGadgetOptionsPageDecorator *gp1 = qobject_cast<const UAVGadgetOptionsPageDecorator *>(p1);
const UAVGadgetOptionsPageDecorator *gp2 = qobject_cast<const UAVGadgetOptionsPageDecorator *>(p2);
if (gp1 && !gp2) {
return false;
}
if (gp2 && !gp1) {
return true;
}
if (const int cc = QString::localeAwareCompare(p1->category(), p2->category())) {
return cc < 0;
}
return QString::localeAwareCompare(p1->id(), p2->id()) < 0;
if (gp2 && !gp1) {
return true;
}
if (const int cc = QString::localeAwareCompare(p1->trCategory(), p2->trCategory())) {
return cc < 0;
}
return QString::localeAwareCompare(p1->trName(), p2->trName()) < 0;
}
Q_DECLARE_METATYPE(::PageData)
// helper to sort by category and id
bool compareOptionsPageByCategoryAndId(const IOptionsPage *p1, const IOptionsPage *p2)
{
const UAVGadgetOptionsPageDecorator *gp1 = qobject_cast<const UAVGadgetOptionsPageDecorator *>(p1);
const UAVGadgetOptionsPageDecorator *gp2 = qobject_cast<const UAVGadgetOptionsPageDecorator *>(p2);
SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId, const QString &pageId) :
QDialog(parent), m_applied(false)
if (gp1 && !gp2) {
return false;
}
if (gp2 && !gp1) {
return true;
}
if (const int cc = QString::localeAwareCompare(p1->category(), p2->category())) {
return cc < 0;
}
return QString::localeAwareCompare(p1->id(), p2->id()) < 0;
}
}
Q_DECLARE_METATYPE(::PageData) SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId, const QString &pageId) :
QDialog(parent), m_applied(false)
{
setupUi(this);
#ifdef Q_OS_MAC
@ -129,8 +126,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId, const
QList<int> sizes;
if (size0 > 0 && size1 > 0) {
sizes << size0 << size1;
}
else {
} else {
sizes << 150 << 300;
}
splitter->setSizes(sizes);
@ -164,7 +160,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId, const
// get all pages and split them between plugin and gadget list
QList<Core::IOptionsPage *> pages = ExtensionSystem::PluginManager::instance()->getObjects<IOptionsPage>();
foreach(IOptionsPage *page, pages) {
foreach(IOptionsPage * page, pages) {
if (qobject_cast<UAVGadgetOptionsPageDecorator *>(page)) {
gadgetPages.append(page);
} else {
@ -182,10 +178,11 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId, const
QTreeWidgetItem *initialItem = 0;
// add plugin pages
foreach(IOptionsPage *page, pluginPages) {
foreach(IOptionsPage * page, pluginPages) {
QTreeWidgetItem *item = addPage(page);
// to automatically expand all plugin categories, uncomment next line
//item->parent()->setExpanded(true);
// item->parent()->setExpanded(true);
if (page->id() == initialPage && page->category() == initialCategory) {
initialItem = item;
}
@ -197,8 +194,9 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId, const
separator->setText(0, QString(30, 0xB7));
// add gadget pages
foreach(IOptionsPage *page, gadgetPages) {
foreach(IOptionsPage * page, gadgetPages) {
QTreeWidgetItem *item = addPage(page);
if (page->id() == initialPage && page->category() == initialCategory) {
initialItem = item;
}
@ -213,7 +211,6 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId, const
}
pageTree->setCurrentItem(initialItem);
}
}
SettingsDialog::~SettingsDialog()
@ -231,9 +228,11 @@ SettingsDialog::~SettingsDialog()
}
}
QTreeWidgetItem *SettingsDialog::addPage(IOptionsPage *page) {
QTreeWidgetItem *SettingsDialog::addPage(IOptionsPage *page)
{
PageData pageData;
pageData.index = m_pages.count();
pageData.index = m_pages.count();
pageData.category = page->category();
pageData.id = page->id();
@ -452,6 +451,7 @@ bool SettingsDialog::execDialog()
void SettingsDialog::done(int val)
{
QSettings *settings = ICore::instance()->settings();
settings->beginGroup("General");
settings->setValue("LastPreferenceCategory", m_currentCategory);

View File

@ -36,11 +36,9 @@
#include "coreplugin/dialogs/ioptionspage.h"
namespace Core {
class UAVGadgetInstanceManager;
namespace Internal {
class SettingsDialog : public QDialog, public::Ui::SettingsDialog {
Q_OBJECT
@ -80,9 +78,7 @@ private:
QTreeWidgetItem *addPage(IOptionsPage *page);
};
} // namespace Internal
} // namespace Core
#endif // SETTINGSDIALOG_H

View File

@ -44,22 +44,22 @@
// USB
#define USB_MAX_DEVICES 10
#define USB_VID 0x20A0
#define USB_PID 0x4117
#define USB_USAGE_PAGE 0xFF9C
#define USB_USAGE 0x0001
#define USB_DEV_SERIAL_LEN 24
#define USB_PID_ANY -1
#define USB_MAX_STRING_SIZE 255
#define USB_MAX_DEVICES 10
#define USB_VID 0x20A0
#define USB_PID 0x4117
#define USB_USAGE_PAGE 0xFF9C
#define USB_USAGE 0x0001
#define USB_DEV_SERIAL_LEN 24
#define USB_PID_ANY -1
#define USB_MAX_STRING_SIZE 255
// ERROR
#define OPHID_NO_ERROR 0
#define OPHID_ERROR_RET -1
#define OPHID_ERROR_POINTER -2
#define OPHID_ERROR_PARAMETER -3
#define OPHID_ERROR_HANDLE -4
#define OPHID_ERROR_INIT -5
#define OPHID_NO_ERROR 0
#define OPHID_ERROR_RET -1
#define OPHID_ERROR_POINTER -2
#define OPHID_ERROR_PARAMETER -3
#define OPHID_ERROR_HANDLE -4
#define OPHID_ERROR_INIT -5
#define OPHID_ERROR_ENUMERATION -6
#endif // OPHID_CONST_H

View File

@ -132,7 +132,7 @@ int opHID_hidapi::open(int max, int vid, int pid, int usage_page, int usage)
int devices_found = false;
struct hid_device_info *current_device_ptr = NULL;
struct hid_device_info *tmp_device_ptr = NULL;
struct hid_device_info **current_device_pptr = &current_device_ptr;
struct hid_device_info * *current_device_pptr = &current_device_ptr;
OPHID_TRACE("IN");
@ -170,7 +170,6 @@ int opHID_hidapi::open(int max, int vid, int pid, int usage_page, int usage)
}
if (devices_found) {
devices_found = 0;
// Go through the list until we can open one
@ -178,7 +177,6 @@ int opHID_hidapi::open(int max, int vid, int pid, int usage_page, int usage)
tmp_device_ptr = current_device_ptr;
while (tmp_device_ptr) {
OPHID_DEBUG("Opening device VID(%04hx).PID(%04hx)",
tmp_device_ptr->vendor_id,
tmp_device_ptr->product_id);

View File

@ -70,10 +70,10 @@ void USBMonitor::deviceEventReceived()
dev = udev_monitor_receive_device(this->monitor);
if (dev) {
//this->monitorNotifier->setEnabled(0);
// this->monitorNotifier->setEnabled(0);
QString action = QString(udev_device_get_action(dev));
QString devtype = QString(udev_device_get_devtype(dev));
qDebug() << "[DEBUG] Action: " << action << " device: " <<devtype;
qDebug() << "[DEBUG] Action: " << action << " device: " << devtype;
if (action == "add" && devtype == "usb_device") {
printPortInfo(dev);
emit deviceDiscovered(makePortInfo(dev));
@ -83,7 +83,7 @@ void USBMonitor::deviceEventReceived()
}
udev_device_unref(dev);
//this->monitorNotifier->setEnabled(1);
// this->monitorNotifier->setEnabled(1);
} else {
OPHID_ERROR("No Device event from udev. Spurious event?.");
}
@ -123,7 +123,7 @@ USBMonitor::USBMonitor(QObject *parent) : QThread(parent)
this->monitor = udev_monitor_new_from_netlink(this->context, "udev");
udev_monitor_filter_add_match_subsystem_devtype(
this->monitor, "usb", NULL);
//udev_monitor_filter_add_match_tag(this->monitor, "openpilot");
// udev_monitor_filter_add_match_tag(this->monitor, "openpilot");
udev_monitor_enable_receiving(this->monitor);
this->monitorNotifier = new QSocketNotifier(
udev_monitor_get_fd(this->monitor), QSocketNotifier::Read, this);
@ -168,7 +168,7 @@ QList<USBPortInfo> USBMonitor::availableDevices()
enumerate = udev_enumerate_new(this->context);
udev_enumerate_add_match_subsystem(enumerate, "usb");
//udev_enumerate_add_match_tag(enumerate, "openpilot");
// udev_enumerate_add_match_tag(enumerate, "openpilot");
udev_enumerate_add_match_sysattr(enumerate, "idVendor", "20a0");
udev_enumerate_scan_devices(enumerate);
devices = udev_enumerate_get_list_entry(enumerate);
@ -216,8 +216,8 @@ QList<USBPortInfo> USBMonitor::availableDevices(int vid, int pid, int bcdDeviceM
QList<USBPortInfo> thePortsWeWant;
foreach(USBPortInfo port, allPorts) {
if ((port.vendorID == vid || vid == -1) &&
(port.productID == pid || pid == -1) &&
if ((port.vendorID == vid || vid == -1) &&
(port.productID == pid || pid == -1) &&
((port.bcdDevice >> 8) == bcdDeviceMSB || bcdDeviceMSB == -1) &&
((port.bcdDevice & 0x00ff) == bcdDeviceLSB || bcdDeviceLSB == -1)) {
OPHID_DEBUG("Append: 0x%X/0x%X/0x%X", port.vendorID, port.productID, port.bcdDevice);

View File

@ -61,7 +61,6 @@ void USBMonitor::deviceEventReceived()
}
/**
* \brief Get the instance of the USBMONITOR
*
@ -74,7 +73,7 @@ USBMonitor *USBMonitor::instance()
/**
* \brief Constructor
* \brief Constructor
*
*/
USBMonitor::USBMonitor(QObject *parent) : QThread(parent)
@ -121,26 +120,26 @@ QList<USBPortInfo> USBMonitor::availableDevices(int vid, int pid, int bcdDeviceM
QList<USBPortInfo> thePortsWeWant;
OPHID_TRACE("IN");
// Print the list
qDebug() << "List off (" << knowndevices.length() << ") devices that are tracked:";
foreach(USBPortInfo info, knowndevices /*thePortsWeWant*/) {
qDebug() << "product:" << info.product
<< " bcdDevice:" << info.bcdDevice
<< " devicePath:" << info.devicePath;
qDebug() << "product:" << info.product
<< " bcdDevice:" << info.bcdDevice
<< " devicePath:" << info.devicePath;
// Filter to return only the one request (if exists)
if ((info.vendorID == vid || vid == -1) &&
(info.productID == pid || pid == -1) &&
((info.bcdDevice >> 8) == bcdDeviceMSB || bcdDeviceMSB == -1) &&
(info.productID == pid || pid == -1) &&
((info.bcdDevice >> 8) == bcdDeviceMSB || bcdDeviceMSB == -1) &&
((info.bcdDevice & 0x00ff) == bcdDeviceLSB || bcdDeviceLSB == -1)) {
thePortsWeWant.append(info);
OPHID_DEBUG("Found device.");
OPHID_DEBUG("Found device.");
}
}
OPHID_TRACE("OUT");
return thePortsWeWant;
}
@ -219,7 +218,7 @@ bool USBRegistrationWidget::winEvent(MSG *message, long *result)
OPHID_TRACE("IN");
qese->onDeviceChangeWin(message->wParam, message->lParam);
*result = 1;
ret = true;
ret = true;
OPHID_TRACE("OUT");
}
@ -229,7 +228,7 @@ bool USBRegistrationWidget::winEvent(MSG *message, long *result)
/**
* \brief filter out the device based on information and populate to be added
* \brief filter out the device based on information and populate to be added
*
* \note Triggered from device plug/unplug windows signal
*
@ -246,9 +245,9 @@ bool USBMonitor::matchAndDispatchChangedDevice(const QString & deviceID, const G
qDebug() << "[STATUS CHANGE] from device ID: " << deviceID;
bool rc;
SP_DEVINFO_DATA spDevInfoData;
DWORD dwFlag = (DBT_DEVICEARRIVAL == wParam) ? DIGCF_PRESENT : 0/*DIGCF_ALLCLASSES*/;
DWORD dwFlag = (DBT_DEVICEARRIVAL == wParam) ? DIGCF_PRESENT : 0 /*DIGCF_ALLCLASSES*/;
HDEVINFO devInfo;
devInfo = SetupDiGetClassDevs(&guid, NULL, NULL, dwFlag | DIGCF_DEVICEINTERFACE);
if (devInfo != INVALID_HANDLE_VALUE) {
@ -256,10 +255,10 @@ bool USBMonitor::matchAndDispatchChangedDevice(const QString & deviceID, const G
for (DWORD i = 0; SetupDiEnumDeviceInfo(devInfo, i, &spDevInfoData); i++) {
DWORD nSize = 0;
TCHAR buf[MAX_PATH];
rc = SetupDiGetDeviceInstanceId(devInfo, &spDevInfoData, buf, MAX_PATH, &nSize);
qDebug() << "Found:" << TCHARToQString(buf);
rc = SetupDiGetDeviceInstanceId(devInfo, &spDevInfoData, buf, MAX_PATH, &nSize);
qDebug() << "Found:" << TCHARToQString(buf);
if (rc && deviceID.contains(TCHARToQString(buf))) {
qDebug() << "[MATCH] " << TCHARToQString(buf);
qDebug() << "[MATCH] " << TCHARToQString(buf);
USBPortInfo info;
info.devicePath = deviceID;
if (wParam == DBT_DEVICEARRIVAL) {
@ -268,37 +267,37 @@ bool USBMonitor::matchAndDispatchChangedDevice(const QString & deviceID, const G
OPHID_ERROR("Not found");
break;
}
if (knowndevices.length()) {
if (knowndevices.length()) {
foreach(USBPortInfo m_info, knowndevices) {
if (m_info.serialNumber == info.serialNumber &&
m_info.productID == info.productID &&
m_info.bcdDevice == info.bcdDevice &&
m_info.devicePath == info.devicePath) {
if (m_info.serialNumber == info.serialNumber &&
m_info.productID == info.productID &&
m_info.bcdDevice == info.bcdDevice &&
m_info.devicePath == info.devicePath) {
OPHID_ERROR("Already present");
break;
}
}
}
}
if (info.bcdDevice == 0 || info.product.isEmpty()) {
OPHID_ERROR("Missing parameters");
break;
}
knowndevices.append(info);
qDebug() << "[SIGNAL] Device discovered on device:"
<< info.product
<< info.bcdDevice;
qDebug() << "[SIGNAL] Device discovered on device:"
<< info.product
<< info.bcdDevice;
emit deviceDiscovered(info);
break;
} else if (wParam == DBT_DEVICEREMOVECOMPLETE) {
for (int x = 0; x < knowndevices.count(); ++x) {
USBPortInfo temp = knowndevices.at(x);
knowndevices.removeAt(x);
qDebug() << "[SIGNAL] Device removed on device:"
<< temp.product
<< temp.bcdDevice;
USBPortInfo temp = knowndevices.at(x);
knowndevices.removeAt(x);
qDebug() << "[SIGNAL] Device removed on device:"
<< temp.product
<< temp.bcdDevice;
}
emit deviceRemoved(info);
break;
break;
}
break;
}
@ -316,10 +315,10 @@ bool USBMonitor::matchAndDispatchChangedDevice(const QString & deviceID, const G
* \return QList
* \retval List of handled devices
*/
QList<USBPortInfo> USBMonitor::availableDevices() {
enumerateDevicesWin(guid_hid);
return knowndevices;
QList<USBPortInfo> USBMonitor::availableDevices()
{
enumerateDevicesWin(guid_hid);
return knowndevices;
}
@ -339,7 +338,7 @@ void USBMonitor::enumerateDevicesWin(const GUID & guid)
SP_DEVINFO_DATA devInfoData;
OPHID_TRACE("IN");
devInfo = SetupDiGetClassDevs(&guid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (devInfo != INVALID_HANDLE_VALUE) {
@ -347,9 +346,9 @@ void USBMonitor::enumerateDevicesWin(const GUID & guid)
for (i = 0; SetupDiEnumDeviceInfo(devInfo, i, &devInfoData); i++) {
int r = infoFromHandle(guid, info, devInfo, i);
if (r == OPHID_NO_ERROR) {
knowndevices.append(info);
j++;
// break;
knowndevices.append(info);
j++;
// break;
} else if (r == OPHID_ERROR_ENUMERATION) {
break;
}
@ -362,7 +361,7 @@ void USBMonitor::enumerateDevicesWin(const GUID & guid)
/**
* \brief filter out the device based on information and populate to be added
* \brief filter out the device based on information and populate to be added
*
* \note Called from pooling during startup and from device plug/unplug windows signal
*
@ -392,7 +391,7 @@ int USBMonitor::infoFromHandle(const GUID & guid, USBPortInfo & info, HDEVINFO &
ret = SetupDiEnumDeviceInterfaces(devInfo, NULL, &guid, index, &iface);
if (!ret) {
ret = OPHID_ERROR_ENUMERATION;
goto leave;
goto leave;
}
// Fill the interface information
@ -400,7 +399,7 @@ int USBMonitor::infoFromHandle(const GUID & guid, USBPortInfo & info, HDEVINFO &
details = (SP_DEVICE_INTERFACE_DETAIL_DATA *)malloc(reqd_size);
if (details == NULL) {
ret = OPHID_ERROR_RET;
goto leave;
goto leave;
}
memset(details, 0, reqd_size);
details->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
@ -408,7 +407,7 @@ int USBMonitor::infoFromHandle(const GUID & guid, USBPortInfo & info, HDEVINFO &
if (!ret) {
free(details);
ret = OPHID_ERROR_RET;
goto leave;
goto leave;
}
qDevicePath = QString().fromWCharArray(details->DevicePath).toUpper();
@ -418,19 +417,19 @@ int USBMonitor::infoFromHandle(const GUID & guid, USBPortInfo & info, HDEVINFO &
goto leave;
}
// Exclude second hid which (probably) is the gamepad controller
if (qDevicePath.contains("COL02")) {
if (qDevicePath.contains("COL02")) {
ret = OPHID_ERROR_RET;
goto leave;
}
qDebug() << "Found device with valid PATH: " << qDevicePath;
h = CreateFile(details->DevicePath,
h = CreateFile(details->DevicePath,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL);
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL);
if (h == INVALID_HANDLE_VALUE) {
DWORD err = GetLastError();
@ -439,42 +438,42 @@ int USBMonitor::infoFromHandle(const GUID & guid, USBPortInfo & info, HDEVINFO &
// Let's not log it :)
if (err == ERROR_ACCESS_DENIED) {
free(details);
ret = OPHID_ERROR_RET;
goto leave;
ret = OPHID_ERROR_RET;
goto leave;
}
qDebug() << "Problem opening handle, path: "
<< QString().fromWCharArray(details->DevicePath);
qDebug() << "Problem opening handle, path: "
<< QString().fromWCharArray(details->DevicePath);
free(details);
ret = OPHID_ERROR_RET;
goto leave;
goto leave;
}
free(details);
attrib.Size = sizeof(HIDD_ATTRIBUTES);
attrib.Size = sizeof(HIDD_ATTRIBUTES);
ret = HidD_GetAttributes(h, &attrib);
info.vendorID = attrib.VendorID;
info.productID = attrib.ProductID;
info.bcdDevice = attrib.VersionNumber;
info.vendorID = attrib.VendorID;
info.productID = attrib.ProductID;
info.bcdDevice = attrib.VersionNumber;
info.devicePath = qDevicePath;
if (attrib.VendorID != 0x20A0) {
CloseHandle(h);
ret = OPHID_ERROR_RET;
goto leave;
CloseHandle(h);
ret = OPHID_ERROR_RET;
goto leave;
}
if (!ret || !HidD_GetPreparsedData(h, &hid_data)) {
CloseHandle(h);
ret = OPHID_ERROR_RET;
goto leave;
goto leave;
}
if (!HidP_GetCaps(hid_data, &capabilities)) {
HidD_FreePreparsedData(hid_data);
CloseHandle(h);
ret = OPHID_ERROR_RET;
goto leave;
goto leave;
}
info.UsagePage = capabilities.UsagePage;
@ -488,7 +487,7 @@ int USBMonitor::infoFromHandle(const GUID & guid, USBPortInfo & info, HDEVINFO &
HidD_GetProductString(h, temp, sizeof(temp));
info.product = QString().fromUtf16((ushort *)temp, -1);
CloseHandle(h);
h = NULL;
h = NULL;
ret = OPHID_NO_ERROR;
leave: