Commit b5651698 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Modernize code

parent 890691b9
Pipeline #138505 passed with stage
in 1 minute and 1 second
......@@ -81,10 +81,10 @@ void KKameraConfig::defaults()
void KKameraConfig::displayGPFailureDialogue()
{
QVBoxLayout *topLayout = new QVBoxLayout(this);
auto topLayout = new QVBoxLayout(this);
topLayout->setSpacing(0);
topLayout->setContentsMargins(0, 0, 0, 0);
QLabel *label = new QLabel(i18n("Unable to initialize the gPhoto2 libraries."), this);
auto label = new QLabel(i18n("Unable to initialize the gPhoto2 libraries."), this);
topLayout->addWidget(label);
}
......@@ -94,7 +94,7 @@ void KKameraConfig::displayGPSuccessDialogue()
setButtons(Help | Apply );
// create a layout with two vertical boxes
QVBoxLayout *topLayout = new QVBoxLayout(this);
auto topLayout = new QVBoxLayout(this);
topLayout->setSpacing(0);
topLayout->setContentsMargins(0, 0, 0, 0);
......@@ -175,7 +175,7 @@ void KKameraConfig::populateDeviceListView()
CameraDevicesMap::ConstIterator itEnd = m_devices.constEnd();
for (CameraDevicesMap::ConstIterator it = m_devices.constBegin(); it != itEnd; ++it) {
if (it.value()) {
QStandardItem *deviceItem = new QStandardItem;
auto deviceItem = new QStandardItem;
deviceItem->setEditable(false);
deviceItem->setText(it.key());
deviceItem->setIcon(QIcon::fromTheme(QStringLiteral("camera-photo")));
......@@ -185,7 +185,7 @@ void KKameraConfig::populateDeviceListView()
slot_deviceSelected(m_deviceSel->currentIndex());
}
void KKameraConfig::save(void)
void KKameraConfig::save()
{
CameraDevicesMap::Iterator it;
......@@ -196,7 +196,7 @@ void KKameraConfig::save(void)
m_config->sync();
}
void KKameraConfig::load(void)
void KKameraConfig::load()
{
QStringList groupList = m_config->groupList();
......@@ -320,12 +320,12 @@ QString KKameraConfig::suggestName(const QString &name)
if (!m_devices.contains(new_name)) return new_name;
}
return QString();
return {};
}
void KKameraConfig::slot_addCamera()
{
KCamera *m_device = new KCamera(QString(), QString());
auto m_device = new KCamera(QString(), QString());
connect(m_device, qOverload<const QString&>(&KCamera::error),
this, qOverload<const QString&>(&KKameraConfig::slot_error));
......@@ -432,7 +432,7 @@ void KKameraConfig::cbGPIdle(GPContext * /*context*/, void * /*data*/)
GPContextFeedback KKameraConfig::cbGPCancel(GPContext * /*context*/, void *data)
{
KKameraConfig *self( reinterpret_cast<KKameraConfig*>(data) );
auto self( reinterpret_cast<KKameraConfig*>(data) );
// Since in practice no camera driver supports idle callbacks yet,
// we'll use the cancel callback as opportunity to process events
......
......@@ -87,7 +87,7 @@ private:
static GPContextFeedback cbGPCancel(GPContext *context, void *data);
private:
typedef QMap<QString, KCamera *> CameraDevicesMap;
using CameraDevicesMap = QMap<QString, KCamera *>;
KConfig *m_config;
CameraDevicesMap m_devices;
......
......@@ -47,11 +47,11 @@ KameraConfigDialog::KameraConfigDialog(Camera */*camera*/,
QDialog(parent),
m_widgetRoot(widget)
{
QDialogButtonBox *buttonBox = new QDialogButtonBox(
auto buttonBox = new QDialogButtonBox(
QDialogButtonBox::Ok|QDialogButtonBox::Cancel, this);
QWidget *mainWidget = new QWidget(this);
QVBoxLayout *mainLayout = new QVBoxLayout;
auto mainWidget = new QWidget(this);
auto mainLayout = new QVBoxLayout;
setLayout(mainLayout);
mainLayout->addWidget(mainWidget);
mainLayout->setContentsMargins(0, 0, 0, 0);
......@@ -65,11 +65,11 @@ KameraConfigDialog::KameraConfigDialog(Camera */*camera*/,
okButton->setDefault(true);
setModal( true );
QFrame *main = new QFrame(this);
auto main = new QFrame(this);
mainLayout->addWidget(main);
// Sets a layout for the frame, which is the parent of the GP_WIDGET_WINDOW
QVBoxLayout *topLayout = new QVBoxLayout(main);
auto topLayout = new QVBoxLayout(main);
topLayout->setContentsMargins(0, 0, 0, 0);
m_tabWidget = nullptr;
......@@ -111,20 +111,20 @@ void KameraConfigDialog::appendWidget(QWidget *parent, CameraWidget *widget)
m_tabWidget = new QTabWidget(parent);
parent->layout()->addWidget(m_tabWidget);
}
QWidget *tab = new QWidget;
auto tab = new QWidget;
// widgets are to be aligned vertically in the tab
QVBoxLayout *tabLayout = new QVBoxLayout(tab);
auto tabLayout = new QVBoxLayout(tab);
tabLayout->setContentsMargins(0, 0, 0, 0);
m_tabWidget->addTab(tab, QString::fromLocal8Bit(widget_label));
// Add scroll area
QScrollArea *scrollArea = new QScrollArea(tab);
auto scrollArea = new QScrollArea(tab);
scrollArea->setWidgetResizable(true);
scrollArea->setFrameShape(QFrame::NoFrame);
tabLayout->addWidget(scrollArea);
// Add a container widget to hold the page
QWidget *tabContainer = new QWidget(tab);
auto tabContainer = new QWidget(tab);
// Add a layout for later parent->layout()->... calls
new QVBoxLayout(tabContainer);
......@@ -140,8 +140,8 @@ void KameraConfigDialog::appendWidget(QWidget *parent, CameraWidget *widget)
case GP_WIDGET_TOGGLE:
{
// Share the QGridLayout code
QWidget *grid = new QWidget(parent);
QGridLayout *gridLayout = new QGridLayout(grid);
auto grid = new QWidget(parent);
auto gridLayout = new QGridLayout(grid);
grid->setLayout(gridLayout);
parent->layout()->addWidget(grid);
......@@ -151,7 +151,7 @@ void KameraConfigDialog::appendWidget(QWidget *parent, CameraWidget *widget)
gp_widget_get_value(widget, &widget_value_string);
label = new QLabel(QString::fromLocal8Bit(widget_label)+QLatin1Char(':'), grid);
QLineEdit *lineEdit = new QLineEdit(widget_value_string, grid);
auto lineEdit = new QLineEdit(widget_value_string, grid);
gridLayout->addWidget(lineEdit, 0, 1, Qt::AlignRight);
m_wmap.insert(widget, lineEdit);
......@@ -165,7 +165,7 @@ void KameraConfigDialog::appendWidget(QWidget *parent, CameraWidget *widget)
gp_widget_get_value(widget, &widget_value_float);
label = new QLabel(QString::fromLocal8Bit(widget_label)+':', grid);
QSlider *slider = new QSlider(Qt::Horizontal, grid);
auto slider = new QSlider(Qt::Horizontal, grid);
gridLayout->addWidget(slider, 0, 1, Qt::AlignRight);
m_wmap.insert(widget, slider);
......@@ -175,7 +175,7 @@ void KameraConfigDialog::appendWidget(QWidget *parent, CameraWidget *widget)
gp_widget_get_value(widget, &widget_value_int);
label = new QLabel(QString::fromLocal8Bit(widget_label), grid);
QCheckBox *checkBox = new QCheckBox(grid);
auto checkBox = new QCheckBox(grid);
checkBox->setChecked(widget_value_int);
gridLayout->addWidget(checkBox, 0, 1, Qt::AlignRight);
......@@ -198,7 +198,7 @@ void KameraConfigDialog::appendWidget(QWidget *parent, CameraWidget *widget)
} else {
layout = new QVBoxLayout;
}
QGroupBox *buttonGroup = new QGroupBox(
auto buttonGroup = new QGroupBox(
QString::fromLocal8Bit(widget_label), parent);
parent->layout()->addWidget(buttonGroup);
......@@ -206,7 +206,7 @@ void KameraConfigDialog::appendWidget(QWidget *parent, CameraWidget *widget)
const char *widget_choice;
gp_widget_get_choice(widget, i, &widget_choice);
QRadioButton *newestButton = new QRadioButton(widget_choice);
auto newestButton = new QRadioButton(widget_choice);
if(widget_value_string && !strcmp(widget_value_string, widget_choice)) {
newestButton->setChecked(true);
}
......@@ -226,7 +226,7 @@ void KameraConfigDialog::appendWidget(QWidget *parent, CameraWidget *widget)
{
gp_widget_get_value(widget, &widget_value_string);
QComboBox *comboBox = new QComboBox(parent);
auto comboBox = new QComboBox(parent);
parent->layout()->addWidget(comboBox);
comboBox->clear();
for(int i = 0; i < gp_widget_count_choices(widget); ++i) {
......@@ -251,7 +251,7 @@ void KameraConfigDialog::appendWidget(QWidget *parent, CameraWidget *widget)
// I can't see a way of implementing this. Since there is
// no way of telling which button sent you a signal, we
// can't map to the appropriate widget->callback
QLabel *label = new QLabel(i18n("Button (not supported by KControl)"), parent);
auto label = new QLabel(i18n("Button (not supported by KControl)"), parent);
parent->layout()->addWidget(label);
break;
......@@ -259,7 +259,7 @@ void KameraConfigDialog::appendWidget(QWidget *parent, CameraWidget *widget)
case GP_WIDGET_DATE:
{
// TODO
QLabel * label = new QLabel(i18n("Date (not supported by KControl)"), parent);
auto label = new QLabel(i18n("Date (not supported by KControl)"), parent);
parent->layout()->addWidget(label);
break;
......@@ -278,10 +278,10 @@ void KameraConfigDialog::appendWidget(QWidget *parent, CameraWidget *widget)
if (widget_type == GP_WIDGET_SECTION) {
// Get latest tab
QWidget *tab = m_tabWidget->widget(m_tabWidget->count()-1);
QScrollArea *scrollArea =
auto scrollArea =
dynamic_cast<QScrollArea *>(tab->children().at(1));
if (scrollArea) {
QVBoxLayout *vbox_layout =
auto vbox_layout =
dynamic_cast<QVBoxLayout *>(scrollArea->widget()->layout());
if (vbox_layout) {
vbox_layout->addStretch();
......@@ -304,14 +304,14 @@ void KameraConfigDialog::updateWidgetValue(CameraWidget *widget)
break;
case GP_WIDGET_TEXT:
{
QLineEdit *lineEdit = static_cast<QLineEdit *>(m_wmap[widget]);
auto lineEdit = static_cast<QLineEdit *>(m_wmap[widget]);
gp_widget_set_value(widget, (void *)lineEdit->text().toLocal8Bit().data());
break;
}
case GP_WIDGET_RANGE:
{
QSlider *slider = static_cast<QSlider *>(m_wmap[widget]);
auto slider = static_cast<QSlider *>(m_wmap[widget]);
float value_float = slider->value();
gp_widget_set_value(widget, (void *)&value_float);
......@@ -319,7 +319,7 @@ void KameraConfigDialog::updateWidgetValue(CameraWidget *widget)
}
case GP_WIDGET_TOGGLE:
{
QCheckBox *checkBox = static_cast<QCheckBox *>(m_wmap[widget]);
auto checkBox = static_cast<QCheckBox *>(m_wmap[widget]);
int value_int = checkBox->isChecked() ? 1 : 0;
gp_widget_set_value(widget, (void *)&value_int);
......@@ -327,9 +327,9 @@ void KameraConfigDialog::updateWidgetValue(CameraWidget *widget)
}
case GP_WIDGET_RADIO:
{
QGroupBox *buttonGroup = static_cast<QGroupBox *>(m_wmap[widget]);
auto buttonGroup = static_cast<QGroupBox *>(m_wmap[widget]);
for (auto button : buttonGroup->children()) {
QRadioButton *radButton = static_cast<QRadioButton *>(button);
auto radButton = static_cast<QRadioButton *>(button);
if (radButton->isChecked()) {
gp_widget_set_value(widget,
(void *)radButton->text().toLocal8Bit().data());
......@@ -340,7 +340,7 @@ void KameraConfigDialog::updateWidgetValue(CameraWidget *widget)
}
case GP_WIDGET_MENU:
{
QComboBox *comboBox = static_cast<QComboBox *>(m_wmap[widget]);
auto comboBox = static_cast<QComboBox *>(m_wmap[widget]);
gp_widget_set_value(widget,
(void *)comboBox->currentText().toLocal8Bit().data());
......
......@@ -306,10 +306,10 @@ KameraDeviceSelectDialog::KameraDeviceSelectDialog(QWidget *parent, KCamera *dev
connect(m_device, qOverload<const QString&, const QString&>(&KCamera::error),
this, qOverload<const QString&, const QString&>(&KameraDeviceSelectDialog::slot_error));
QWidget *page = new QWidget( this );
auto page = new QWidget( this );
// a layout with horizontal boxes - this gives the two columns
QHBoxLayout *topLayout = new QHBoxLayout(page);
auto topLayout = new QHBoxLayout(page);
topLayout->setContentsMargins(0, 0, 0, 0);
// the models list
......@@ -328,12 +328,12 @@ KameraDeviceSelectDialog::KameraDeviceSelectDialog(QWidget *parent, KCamera *dev
m_modelSel->setSizePolicy(QSizePolicy(QSizePolicy::Maximum,
QSizePolicy::Preferred));
QVBoxLayout *rightLayout = new QVBoxLayout();
auto rightLayout = new QVBoxLayout();
rightLayout->setContentsMargins(0, 0, 0, 0);
topLayout->addLayout( rightLayout );
m_portSelectGroup = new QGroupBox(i18n("Port"), page);
QVBoxLayout *vertLayout = new QVBoxLayout;
auto vertLayout = new QVBoxLayout;
m_portSelectGroup->setLayout( vertLayout );
m_portSelectGroup->setMinimumSize(100, 120);
rightLayout->addWidget(m_portSelectGroup);
......@@ -349,15 +349,15 @@ KameraDeviceSelectDialog::KameraDeviceSelectDialog(QWidget *parent, KCamera *dev
"be connected to one of the computer's USB ports, or to a USB hub."));
m_portSettingsGroup = new QGroupBox(i18n("Port Settings"), page);
QVBoxLayout *lay = new QVBoxLayout;
auto lay = new QVBoxLayout;
m_portSettingsGroup->setLayout( lay );
rightLayout->addWidget(m_portSettingsGroup);
// Create port settings widget stack
m_settingsStack = new QStackedWidget;
QWidget *grid2 = new QWidget(m_settingsStack);
QGridLayout *gridLayout2 = new QGridLayout(grid2);
auto grid2 = new QWidget(m_settingsStack);
auto gridLayout2 = new QGridLayout(grid2);
grid2->setLayout(gridLayout2);
QLabel *label2 = new QLabel(i18n("Port"), grid2);
auto label2 = new QLabel(i18n("Port"), grid2);
gridLayout2->addWidget(label2, 0, 0, Qt::AlignLeft);
lay->addWidget(grid2);
......@@ -371,11 +371,11 @@ KameraDeviceSelectDialog::KameraDeviceSelectDialog(QWidget *parent, KCamera *dev
m_settingsStack));
// serial tab
QWidget *grid = new QWidget(m_settingsStack);
QGridLayout *gridLayout = new QGridLayout(grid);
auto grid = new QWidget(m_settingsStack);
auto gridLayout = new QGridLayout(grid);
grid->setLayout(gridLayout);
QLabel *label = new QLabel(i18n("Port:"), grid);
auto label = new QLabel(i18n("Port:"), grid);
m_serialPortCombo = new QComboBox(grid);
m_serialPortCombo->setEditable(true);
m_serialPortCombo->setWhatsThis( i18n("Specify here the serial port to "
......@@ -444,7 +444,7 @@ KameraDeviceSelectDialog::KameraDeviceSelectDialog(QWidget *parent, KCamera *dev
void KameraDeviceSelectDialog::changeCurrentIndex()
{
QRadioButton *send = dynamic_cast<QRadioButton*>( sender() );
auto send = dynamic_cast<QRadioButton*>( sender() );
if ( send ) {
if ( send == m_serialRB ) {
m_settingsStack->setCurrentIndex( INDEX_SERIAL );
......@@ -467,7 +467,7 @@ bool KameraDeviceSelectDialog::populateCameraListView()
} else {
for(int x = 0; x < numCams; ++x) {
if(gp_abilities_list_get_abilities(m_device->m_abilitylist, x, &a) == GP_OK) {
QStandardItem *cameraItem = new QStandardItem;
auto cameraItem = new QStandardItem;
cameraItem->setEditable(false);
cameraItem->setText(a.model);
m_model->appendRow(cameraItem);
......
......@@ -100,7 +100,7 @@ protected Q_SLOTS:
protected:
KCamera *m_device;
bool populateCameraListView(void);
bool populateCameraListView();
void setPortType(int type);
// port settings widgets
......
......@@ -25,14 +25,14 @@
// #undef QT_NO_DEBUG
#include "kamera.h"
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <cerrno>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include <QFile>
#include <QTextStream>
......@@ -213,7 +213,7 @@ bool KameraProtocol::openCamera(QString &str) {
}
// should be done after operations over the wire
void KameraProtocol::closeCamera(void)
void KameraProtocol::closeCamera()
{
int gpr;
......@@ -443,7 +443,7 @@ void KameraProtocol::stat(const QUrl &url)
}
// Implements stat("/") -- which always returns the same value.
void KameraProtocol::statRoot(void)
void KameraProtocol::statRoot()
{
KIO::UDSEntry entry;
......@@ -962,7 +962,7 @@ void KameraProtocol::setCamera(const QString& camera, const QString& port)
}
}
void KameraProtocol::reparseConfiguration(void)
void KameraProtocol::reparseConfiguration()
{
// we have no global config, do we?
}
......@@ -1038,17 +1038,17 @@ void KameraProtocol::translateDirectoryToUDS(KIO::UDSEntry &udsEntry,
udsEntry.fastInsert(KIO::UDSEntry::UDS_MIME_TYPE, QStringLiteral("inode/directory"));
}
bool KameraProtocol::cameraSupportsDel(void)
bool KameraProtocol::cameraSupportsDel()
{
return (m_abilities.file_operations & GP_FILE_OPERATION_DELETE);
}
bool KameraProtocol::cameraSupportsPut(void)
bool KameraProtocol::cameraSupportsPut()
{
return (m_abilities.folder_operations & GP_FOLDER_OPERATION_PUT_FILE);
}
bool KameraProtocol::cameraSupportsPreview(void)
bool KameraProtocol::cameraSupportsPreview()
{
return (m_abilities.file_operations & GP_FILE_OPERATION_PREVIEW);
}
......@@ -1073,7 +1073,7 @@ int KameraProtocol::readCameraFolder(const QString &folder,
void frontendProgressUpdate(
GPContext * /*context*/, unsigned int /*id*/, float /*current*/, void *data
) {
KameraProtocol *object = (KameraProtocol*)data;
auto object = (KameraProtocol*)data;
// This code will get the last chunk of data retrieved from the
// camera and pass it to KIO, to allow progressive display
......@@ -1112,7 +1112,7 @@ unsigned int frontendProgressStart(
#endif
void *data
) {
KameraProtocol *object = (KameraProtocol*)data;
auto object = (KameraProtocol*)data;
#ifndef HAVE_GPHOTO2_5
char *status;
......@@ -1165,7 +1165,7 @@ static void frontendCameraStatus(
#endif
void *data
) {
KameraProtocol *object = (KameraProtocol*)data;
auto object = (KameraProtocol*)data;
#ifndef HAVE_GPHOTO2_5
char *status;
......
......@@ -58,15 +58,15 @@ private:
void split_url2camerapath(const QString &url, QString &directory, QString &file);
void setCamera(const QString &cam, const QString &port);
void reparseConfiguration(void) override;
void reparseConfiguration() override;
bool openCamera(QString& str);
bool openCamera(void ) {
bool openCamera( ) {
QString errstr;
return openCamera(errstr);
}
void closeCamera(void);
void closeCamera();
void statRoot(void);
void statRoot();
void statRegular(const QUrl &url);
void translateTextToUDS(KIO::UDSEntry &udsEntry,
const QString &info,
......@@ -75,9 +75,9 @@ private:
const CameraFileInfo &info,
const QString &name);
void translateDirectoryToUDS(KIO::UDSEntry &udsEntry, const QString &dirname);
bool cameraSupportsPreview(void);
bool cameraSupportsDel(void);
bool cameraSupportsPut(void);
bool cameraSupportsPreview();
bool cameraSupportsDel();
bool cameraSupportsPut();
int readCameraFolder(const QString &folder,
CameraList *dirList,
CameraList *fileList);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment