summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPavel Shlyak2018-12-30 18:31:11 +0100
committerAlf Gaida2018-12-30 18:31:11 +0100
commit1dbc6087e5af4288011a9cc8942282fc144cfcb6 (patch)
treebc0063b51e9c7733c5483a1babaa16b9af108015 /src
parentTranslated using Weblate (Turkish) (diff)
downloadpavucontrol-slx-1dbc6087e5af4288011a9cc8942282fc144cfcb6.tar.gz
pavucontrol-slx-1dbc6087e5af4288011a9cc8942282fc144cfcb6.tar.xz
pavucontrol-slx-1dbc6087e5af4288011a9cc8942282fc144cfcb6.zip
Some more code modernization (#111)
* Empty instead of size * Range based loops
Diffstat (limited to 'src')
-rw-r--r--src/cardwidget.cc3
-rw-r--r--src/devicewidget.cc12
-rw-r--r--src/mainwindow.cc101
-rw-r--r--src/pavucontrol.cc6
-rw-r--r--src/sinkinputwidget.cc4
-rw-r--r--src/sinkwidget.cc6
-rw-r--r--src/sourceoutputwidget.cc4
-rw-r--r--src/streamwidget.cc4
8 files changed, 69 insertions, 71 deletions
diff --git a/src/cardwidget.cc b/src/cardwidget.cc
index f86ff30..d5b4e63 100644
--- a/src/cardwidget.cc
+++ b/src/cardwidget.cc
@@ -39,8 +39,7 @@ void CardWidget::prepareMenu() {
profileList->clear();
/* Fill the ComboBox */
- for (uint32_t i = 0; i < profiles.size(); ++i) {
- const auto& profile = profiles[i];
+ for (const auto & profile : profiles) {
QByteArray name = profile.first;
// skip the "off" profile
if (name == noInOutProfile)
diff --git a/src/devicewidget.cc b/src/devicewidget.cc
index c27b4fd..6995f21 100644
--- a/src/devicewidget.cc
+++ b/src/devicewidget.cc
@@ -60,8 +60,8 @@ DeviceWidget::DeviceWidget(MainWindow* parent, QByteArray deviceType) :
connect(portList, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &DeviceWidget::onPortChange);
connect(offsetButton, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &DeviceWidget::onOffsetChange);
- for (unsigned i = 0; i < PA_CHANNELS_MAX; i++)
- channels[i] = nullptr;
+ for (auto & channel : channels)
+ channel = nullptr;
// FIXME:
@@ -189,11 +189,11 @@ void DeviceWidget::prepareMenu() {
portList->clear();
/* Fill the ComboBox's Model */
- for (uint32_t i = 0; i < ports.size(); ++i) {
- QByteArray name = ports[i].first;
- QString desc = ports[i].second;
+ for (auto & port : ports) {
+ QByteArray name = port.first;
+ QString desc = port.second;
portList->addItem(desc, name);
- if (ports[i].first == activePort)
+ if (port.first == activePort)
active_idx = idx;
idx++;
}
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index a9247d6..2030cf1 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -145,9 +145,9 @@ static void updatePorts(DeviceWidget *w, std::map<QByteArray, PortInfo> &ports)
std::map<QByteArray, PortInfo>::iterator it;
PortInfo p;
- for (uint32_t i = 0; i < w->ports.size(); i++) {
+ for (auto & port : w->ports) {
QByteArray desc;
- it = ports.find(w->ports[i].first);
+ it = ports.find(port.first);
if (it == ports.end())
continue;
@@ -165,7 +165,7 @@ static void updatePorts(DeviceWidget *w, std::map<QByteArray, PortInfo> &ports)
desc += MainWindow::tr(" (unplugged)").toUtf8().constData();
}
- w->ports[i].second = desc;
+ port.second = desc;
}
it = ports.find(w->activePort);
@@ -232,9 +232,8 @@ void MainWindow::updateCard(const pa_card_info &info) {
}
w->profiles.clear();
- for (auto profileIt = profile_priorities.cbegin(); profileIt != profile_priorities.cend(); ++profileIt) {
+ for (auto p_profile : profile_priorities) {
bool hasNo = false, hasOther = false;
- pa_card_profile_info2 const * const p_profile = *profileIt;
std::map<QByteArray, PortInfo>::iterator portIt;
QByteArray desc = p_profile->description;
@@ -350,8 +349,8 @@ bool MainWindow::updateSink(const pa_sink_info &info) {
}
w->ports.clear();
- for (auto i = port_priorities.begin(); i != port_priorities.end(); ++i)
- w->ports.push_back(std::pair<QByteArray,QByteArray>(i->name, i->description));
+ for (const auto & port_prioritie : port_priorities)
+ w->ports.push_back(std::pair<QByteArray,QByteArray>(port_prioritie.name, port_prioritie.description));
w->activePort = info.active_port ? info.active_port->name : "";
@@ -517,8 +516,8 @@ void MainWindow::updateSource(const pa_source_info &info) {
w->ports.clear();
- for (auto i = port_priorities.begin(); i != port_priorities.end(); ++i)
- w->ports.push_back(std::pair<QByteArray,QByteArray>(i->name, i->description));
+ for (const auto & port_prioritie : port_priorities)
+ w->ports.push_back(std::pair<QByteArray,QByteArray>(port_prioritie.name, port_prioritie.description));
w->activePort = info.active_port ? info.active_port->name : "";
@@ -701,8 +700,8 @@ void MainWindow::updateClient(const pa_client_info &info) {
g_free(clientNames[info.index]);
clientNames[info.index] = g_strdup(info.name);
- for (auto i = sinkInputWidgets.begin(); i != sinkInputWidgets.end(); ++i) {
- SinkInputWidget *w = i->second;
+ for (auto & sinkInputWidget : sinkInputWidgets) {
+ SinkInputWidget *w = sinkInputWidget.second;
if (!w)
continue;
@@ -719,8 +718,8 @@ void MainWindow::updateServer(const pa_server_info &info) {
defaultSourceName = info.default_source_name ? info.default_source_name : "";
defaultSinkName = info.default_sink_name ? info.default_sink_name : "";
- for (auto i = sinkWidgets.begin(); i != sinkWidgets.end(); ++i) {
- SinkWidget *w = i->second;
+ for (auto & sinkWidget : sinkWidgets) {
+ SinkWidget *w = sinkWidget.second;
if (!w)
continue;
@@ -731,8 +730,8 @@ void MainWindow::updateServer(const pa_server_info &info) {
w->updating = false;
}
- for (auto i = sourceWidgets.begin(); i != sourceWidgets.end(); ++i) {
- SourceWidget *w = i->second;
+ for (auto & sourceWidget : sourceWidgets) {
+ SourceWidget *w = sourceWidget.second;
if (!w)
continue;
@@ -848,22 +847,22 @@ void MainWindow::updateVolumeMeter(uint32_t source_index, uint32_t sink_input_id
} else {
- for (auto i = sinkWidgets.begin(); i != sinkWidgets.end(); ++i) {
- SinkWidget* w = i->second;
+ for (auto & sinkWidget : sinkWidgets) {
+ SinkWidget* w = sinkWidget.second;
if (w->monitor_index == source_index)
w->updatePeak(v);
}
- for (auto i = sourceWidgets.begin(); i != sourceWidgets.end(); ++i) {
- SourceWidget* w = i->second;
+ for (auto & sourceWidget : sourceWidgets) {
+ SourceWidget* w = sourceWidget.second;
if (w->index == source_index)
w->updatePeak(v);
}
- for (auto i = sourceOutputWidgets.begin(); i != sourceOutputWidgets.end(); ++i) {
- SourceOutputWidget* w = i->second;
+ for (auto & sourceOutputWidget : sourceOutputWidgets) {
+ SourceOutputWidget* w = sourceOutputWidget.second;
if (w->sourceIndex() == source_index)
w->updatePeak(v);
@@ -903,8 +902,8 @@ void MainWindow::updateDeviceVisibility() {
void MainWindow::reallyUpdateDeviceVisibility() {
bool is_empty = true;
- for (auto i = sinkInputWidgets.begin(); i != sinkInputWidgets.end(); ++i) {
- SinkInputWidget* w = i->second;
+ for (auto & sinkInputWidget : sinkInputWidgets) {
+ SinkInputWidget* w = sinkInputWidget.second;
if (sinkWidgets.size() > 1) {
w->directionLabel->show();
@@ -931,8 +930,8 @@ void MainWindow::reallyUpdateDeviceVisibility() {
is_empty = true;
- for (auto i = sourceOutputWidgets.begin(); i != sourceOutputWidgets.end(); ++i) {
- SourceOutputWidget* w = i->second;
+ for (auto & sourceOutputWidget : sourceOutputWidgets) {
+ SourceOutputWidget* w = sourceOutputWidget.second;
if (sourceWidgets.size() > 1) {
w->directionLabel->show();
@@ -956,8 +955,8 @@ void MainWindow::reallyUpdateDeviceVisibility() {
is_empty = true;
- for (auto i = sinkWidgets.begin(); i != sinkWidgets.end(); ++i) {
- SinkWidget* w = i->second;
+ for (auto & sinkWidget : sinkWidgets) {
+ SinkWidget* w = sinkWidget.second;
if (showSinkType == SINK_ALL || w->type == showSinkType) {
w->show();
@@ -973,8 +972,8 @@ void MainWindow::reallyUpdateDeviceVisibility() {
is_empty = true;
- for (auto i = cardWidgets.begin(); i != cardWidgets.end(); ++i) {
- CardWidget* w = i->second;
+ for (auto & cardWidget : cardWidgets) {
+ CardWidget* w = cardWidget.second;
w->show();
is_empty = false;
@@ -987,8 +986,8 @@ void MainWindow::reallyUpdateDeviceVisibility() {
is_empty = true;
- for (auto i = sourceWidgets.begin(); i != sourceWidgets.end(); ++i) {
- SourceWidget* w = i->second;
+ for (auto & sourceWidget : sourceWidgets) {
+ SourceWidget* w = sourceWidget.second;
if (showSourceType == SOURCE_ALL ||
w->type == showSourceType ||
@@ -1069,18 +1068,18 @@ void MainWindow::removeClient(uint32_t index) {
}
void MainWindow::removeAllWidgets() {
- for (auto it = sinkInputWidgets.begin(); it != sinkInputWidgets.end(); ++it)
- removeSinkInput(it->first);
- for (auto it = sourceOutputWidgets.begin(); it != sourceOutputWidgets.end(); ++it)
- removeSourceOutput(it->first);
- for (auto it = sinkWidgets.begin(); it != sinkWidgets.end(); ++it)
- removeSink(it->first);
- for (auto it = sourceWidgets.begin(); it != sourceWidgets.end(); ++it)
- removeSource(it->first);
- for (auto it = cardWidgets.begin(); it != cardWidgets.end(); ++it)
- removeCard(it->first);
- for (auto it = clientNames.begin(); it != clientNames.end(); ++it)
- removeClient(it->first);
+ for (auto & sinkInputWidget : sinkInputWidgets)
+ removeSinkInput(sinkInputWidget.first);
+ for (auto & sourceOutputWidget : sourceOutputWidgets)
+ removeSourceOutput(sourceOutputWidget.first);
+ for (auto & sinkWidget : sinkWidgets)
+ removeSink(sinkWidget.first);
+ for (auto & sourceWidget : sourceWidgets)
+ removeSource(sourceWidget.first);
+ for (auto & cardWidget : cardWidgets)
+ removeCard(cardWidget.first);
+ for (auto & clientName : clientNames)
+ removeClient(clientName.first);
deleteEventRoleWidget();
}
@@ -1135,8 +1134,8 @@ void MainWindow::onShowVolumeMetersCheckButtonToggled(bool toggled) {
bool state = showVolumeMetersCheckButton->isChecked();
pa_operation *o;
- for (auto it = sinkWidgets.begin() ; it != sinkWidgets.end(); it++) {
- SinkWidget *sw = it->second;
+ for (auto & sinkWidget : sinkWidgets) {
+ SinkWidget *sw = sinkWidget.second;
if (sw->peak) {
o = pa_stream_cork(sw->peak, (int)!state, nullptr, nullptr);
if (o)
@@ -1144,8 +1143,8 @@ void MainWindow::onShowVolumeMetersCheckButtonToggled(bool toggled) {
}
sw->setVolumeMeterVisible(state);
}
- for (auto it = sourceWidgets.begin() ; it != sourceWidgets.end(); it++) {
- SourceWidget *sw = it->second;
+ for (auto & sourceWidget : sourceWidgets) {
+ SourceWidget *sw = sourceWidget.second;
if (sw->peak) {
o = pa_stream_cork(sw->peak, (int)!state, nullptr, nullptr);
if (o)
@@ -1153,8 +1152,8 @@ void MainWindow::onShowVolumeMetersCheckButtonToggled(bool toggled) {
}
sw->setVolumeMeterVisible(state);
}
- for (auto it = sinkInputWidgets.begin() ; it != sinkInputWidgets.end(); it++) {
- SinkInputWidget *sw = it->second;
+ for (auto & sinkInputWidget : sinkInputWidgets) {
+ SinkInputWidget *sw = sinkInputWidget.second;
if (sw->peak) {
o = pa_stream_cork(sw->peak, (int)!state, nullptr, nullptr);
if (o)
@@ -1162,8 +1161,8 @@ void MainWindow::onShowVolumeMetersCheckButtonToggled(bool toggled) {
}
sw->setVolumeMeterVisible(state);
}
- for (auto it = sourceOutputWidgets.begin() ; it != sourceOutputWidgets.end(); it++) {
- SourceOutputWidget *sw = it->second;
+ for (auto & sourceOutputWidget : sourceOutputWidgets) {
+ SourceOutputWidget *sw = sourceOutputWidget.second;
if (sw->peak) {
o = pa_stream_cork(sw->peak, (int)!state, nullptr, nullptr);
if (o)
diff --git a/src/pavucontrol.cc b/src/pavucontrol.cc
index 1692a8d..28654bd 100644
--- a/src/pavucontrol.cc
+++ b/src/pavucontrol.cc
@@ -179,11 +179,11 @@ void source_output_cb(pa_context *, const pa_source_output_info *i, int eol, voi
* let's open one that isn't empty */
if (default_tab != -1) {
if (default_tab < 1 || default_tab > w->notebook->count()) {
- if (w->sinkInputWidgets.size() > 0)
+ if (!w->sinkInputWidgets.empty())
w->notebook->setCurrentIndex(0);
- else if (w->sourceOutputWidgets.size() > 0)
+ else if (!w->sourceOutputWidgets.empty())
w->notebook->setCurrentIndex(1);
- else if (w->sourceWidgets.size() > 0 && w->sinkWidgets.size() == 0)
+ else if (!w->sourceWidgets.empty() && w->sinkWidgets.empty())
w->notebook->setCurrentIndex(3);
else
w->notebook->setCurrentIndex(2);
diff --git a/src/sinkinputwidget.cc b/src/sinkinputwidget.cc
index 9ede3af..bda7028 100644
--- a/src/sinkinputwidget.cc
+++ b/src/sinkinputwidget.cc
@@ -94,8 +94,8 @@ void SinkInputWidget::onKill() {
}
void SinkInputWidget::buildMenu() {
- for (auto i = mpMainWindow->sinkWidgets.begin(); i != mpMainWindow->sinkWidgets.end(); ++i) {
- menu->addAction(new SinkMenuItem{this, i->second->description, i->second->index, i->second->index == mSinkIndex, menu});
+ for (auto & sinkWidget : mpMainWindow->sinkWidgets) {
+ menu->addAction(new SinkMenuItem{this, sinkWidget.second->description, sinkWidget.second->index, sinkWidget.second->index == mSinkIndex, menu});
}
}
diff --git a/src/sinkwidget.cc b/src/sinkwidget.cc
index f91a99a..b4c6815 100644
--- a/src/sinkwidget.cc
+++ b/src/sinkwidget.cc
@@ -154,10 +154,10 @@ void SinkWidget::onEncodingsChange() {
formats = (pa_format_info**)malloc(sizeof(pa_format_info*) * PAVU_NUM_ENCODINGS);
- for (int i = 0; i < PAVU_NUM_ENCODINGS; ++i) {
- if (encodings[i].widget->isChecked()) {
+ for (auto & encoding : encodings) {
+ if (encoding.widget->isChecked()) {
formats[n_formats] = pa_format_info_new();
- formats[n_formats]->encoding = encodings[i].encoding;
+ formats[n_formats]->encoding = encoding.encoding;
++n_formats;
}
}
diff --git a/src/sourceoutputwidget.cc b/src/sourceoutputwidget.cc
index 966d872..63494ed 100644
--- a/src/sourceoutputwidget.cc
+++ b/src/sourceoutputwidget.cc
@@ -104,8 +104,8 @@ void SourceOutputWidget::onKill() {
void SourceOutputWidget::buildMenu() {
- for (auto i = mpMainWindow->sourceWidgets.begin(); i != mpMainWindow->sourceWidgets.end(); ++i) {
- menu->addAction(new SourceMenuItem{this, i->second->description, i->second->index, i->second->index == mSourceIndex, menu});
+ for (auto & sourceWidget : mpMainWindow->sourceWidgets) {
+ menu->addAction(new SourceMenuItem{this, sourceWidget.second->description, sourceWidget.second->index, sourceWidget.second->index == mSourceIndex, menu});
}
}
diff --git a/src/streamwidget.cc b/src/streamwidget.cc
index d55a3fd..f7b06e0 100644
--- a/src/streamwidget.cc
+++ b/src/streamwidget.cc
@@ -48,8 +48,8 @@ StreamWidget::StreamWidget(MainWindow *parent) :
addAction(terminate);
setContextMenuPolicy(Qt::ActionsContextMenu);
- for (unsigned i = 0; i < PA_CHANNELS_MAX; i++)
- channels[i] = nullptr;
+ for (auto & channel : channels)
+ channel = nullptr;
}
void StreamWidget::setChannelMap(const pa_channel_map &m, bool can_decibel) {