summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLuís Pereira2019-05-17 19:19:04 +0200
committerAlf Gaida2019-05-26 14:52:13 +0200
commitf5190e990260769698c897364d56f866fef733a3 (patch)
tree37294379c2f14f0c2ce2e20a56024574f160ddeb /src
parentAvoid char raw strings literals memory allocations (diff)
downloadpavucontrol-slx-f5190e990260769698c897364d56f866fef733a3.tar.gz
pavucontrol-slx-f5190e990260769698c897364d56f866fef733a3.tar.xz
pavucontrol-slx-f5190e990260769698c897364d56f866fef733a3.zip
Don't use automatic string conversions
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt9
-rw-r--r--src/devicewidget.cc6
-rw-r--r--src/mainwindow.cc36
-rw-r--r--src/pavucontrol.cc4
-rw-r--r--src/rolewidget.cc2
-rw-r--r--src/sinkinputwidget.cc6
-rw-r--r--src/sinkinputwidget.h2
-rw-r--r--src/sinkwidget.cc2
-rw-r--r--src/sourceoutputwidget.cc10
-rw-r--r--src/sourceoutputwidget.h2
-rw-r--r--src/sourcewidget.cc2
11 files changed, 45 insertions, 36 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 89b0272..d6e83da 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -69,6 +69,15 @@ set_property(
PAVUCONTROL_QT_DATA_DIR="${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}"
)
+target_compile_definitions(pavucontrol-qt
+ PRIVATE
+ QT_USE_QSTRINGBUILDER
+ QT_NO_CAST_FROM_ASCII
+ QT_NO_CAST_TO_ASCII
+ QT_NO_URL_CAST_FROM_STRING
+ QT_NO_CAST_FROM_BYTEARRAY
+)
+
target_link_libraries(pavucontrol-qt
Qt5::Widgets
Qt5::DBus
diff --git a/src/devicewidget.cc b/src/devicewidget.cc
index 6995f21..85c856a 100644
--- a/src/devicewidget.cc
+++ b/src/devicewidget.cc
@@ -151,7 +151,7 @@ void DeviceWidget::onOffsetChange() {
card_name = QByteArray::fromStdString(card_stream.str());
if (!(o = pa_context_set_port_latency_offset(get_context(),
- card_name, activePort, offset, nullptr, nullptr))) {
+ card_name.constData(), activePort.constData(), offset, nullptr, nullptr))) {
show_error(tr("pa_context_set_port_latency_offset() failed").toUtf8().constData());
return;
}
@@ -191,7 +191,7 @@ void DeviceWidget::prepareMenu() {
/* Fill the ComboBox's Model */
for (auto & port : ports) {
QByteArray name = port.first;
- QString desc = port.second;
+ QString desc = QString::fromUtf8(port.second);
portList->addItem(desc, name);
if (port.first == activePort)
active_idx = idx;
@@ -228,7 +228,7 @@ void DeviceWidget::renamePopup() {
return;
}
- const QString old_name = description.constData();
+ const QString old_name = QString::fromUtf8(description);
bool ok;
const QString new_name = QInputDialog::getText(this, QCoreApplication::organizationName(), tr("Rename device %1 to:").arg(old_name)
, QLineEdit::Normal, old_name, &ok);
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index c7f2718..83e4964 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -177,7 +177,7 @@ static void updatePorts(DeviceWidget *w, std::map<QByteArray, PortInfo> &ports)
}
static void setIconByName(QLabel* label, const char* name) {
- QIcon icon = QIcon::fromTheme(name);
+ QIcon icon = QIcon::fromTheme(QString::fromUtf8(name));
int size = label->style()->pixelMetric(QStyle::PM_ToolBarIconSize);
QPixmap pix = icon.pixmap(size, size);
label->setPixmap(pix);
@@ -202,7 +202,7 @@ void MainWindow::updateCard(const pa_card_info &info) {
description = pa_proplist_gets(info.proplist, PA_PROP_DEVICE_DESCRIPTION);
w->name = description ? description : info.name;
- w->nameLabel->setText(w->name);
+ w->nameLabel->setText(QString::fromUtf8(w->name));
icon = pa_proplist_gets(info.proplist, PA_PROP_DEVICE_ICON_NAME);
setIconByName(w->iconImage, icon ? icon : "audio-card");
@@ -330,9 +330,9 @@ bool MainWindow::updateSink(const pa_sink_info &info) {
w->type = info.flags & PA_SINK_HARDWARE ? SINK_HARDWARE : SINK_VIRTUAL;
w->boldNameLabel->setText(QLatin1String(""));
- gchar *txt;
- w->nameLabel->setText(txt = g_markup_printf_escaped("%s", info.description));
- w->nameLabel->setToolTip(info.description);
+ gchar *txt = g_markup_printf_escaped("%s", info.description);
+ w->nameLabel->setText(QString::fromUtf8(static_cast<char*>(txt)));
+ w->nameLabel->setToolTip(QString::fromUtf8(info.description));
g_free(txt);
icon = pa_proplist_gets(info.proplist, PA_PROP_DEVICE_ICON_NAME);
@@ -496,9 +496,9 @@ void MainWindow::updateSource(const pa_source_info &info) {
w->type = info.monitor_of_sink != PA_INVALID_INDEX ? SOURCE_MONITOR : (info.flags & PA_SOURCE_HARDWARE ? SOURCE_HARDWARE : SOURCE_VIRTUAL);
w->boldNameLabel->setText(QLatin1String(""));
- gchar *txt;
- w->nameLabel->setText(txt = g_markup_printf_escaped("%s", info.description));
- w->nameLabel->setToolTip(info.description);
+ gchar *txt = g_markup_printf_escaped("%s", info.description);
+ w->nameLabel->setText(QString::fromUtf8(static_cast<char*>(txt)));
+ w->nameLabel->setToolTip(QString::fromUtf8(info.description));
g_free(txt);
icon = pa_proplist_gets(info.proplist, PA_PROP_DEVICE_ICON_NAME);
@@ -616,16 +616,16 @@ void MainWindow::updateSinkInput(const pa_sink_input_info &info) {
char *txt;
if (clientNames.count(info.client)) {
- w->boldNameLabel->setText(txt = g_markup_printf_escaped("<b>%s</b>", clientNames[info.client]));
+ w->boldNameLabel->setText(QString::fromUtf8(txt = g_markup_printf_escaped("<b>%s</b>", clientNames[info.client])));
g_free(txt);
- w->nameLabel->setText(txt = g_markup_printf_escaped(": %s", info.name));
+ w->nameLabel->setText(QString::fromUtf8(txt = g_markup_printf_escaped(": %s", info.name)));
g_free(txt);
} else {
w->boldNameLabel->setText(QLatin1String(""));
- w->nameLabel->setText(info.name);
+ w->nameLabel->setText(QString::fromUtf8(info.name));
}
- w->nameLabel->setToolTip(info.name);
+ w->nameLabel->setToolTip(QString::fromUtf8(info.name));
setIconFromProplist(w->iconImage, info.proplist, "audio-card");
@@ -672,16 +672,16 @@ void MainWindow::updateSourceOutput(const pa_source_output_info &info) {
char *txt;
if (clientNames.count(info.client)) {
- w->boldNameLabel->setText(txt = g_markup_printf_escaped("<b>%s</b>", clientNames[info.client]));
+ w->boldNameLabel->setText(QString::fromUtf8(txt = g_markup_printf_escaped("<b>%s</b>", clientNames[info.client])));
g_free(txt);
- w->nameLabel->setText(txt = g_markup_printf_escaped(": %s", info.name));
+ w->nameLabel->setText(QString::fromUtf8(txt = g_markup_printf_escaped(": %s", info.name)));
g_free(txt);
} else {
w->boldNameLabel->setText(QLatin1String(""));
- w->nameLabel->setText(info.name);
+ w->nameLabel->setText(QString::fromUtf8(info.name));
}
- w->nameLabel->setToolTip(info.name);
+ w->nameLabel->setToolTip(QString::fromUtf8(info.name));
setIconFromProplist(w->iconImage, info.proplist, "audio-input-microphone");
@@ -708,7 +708,7 @@ void MainWindow::updateClient(const pa_client_info &info) {
if (w->clientIndex == info.index) {
gchar *txt;
- w->boldNameLabel->setText(txt = g_markup_printf_escaped("<b>%s</b>", info.name));
+ w->boldNameLabel->setText(QString::fromUtf8(txt = g_markup_printf_escaped("<b>%s</b>", info.name)));
g_free(txt);
}
}
@@ -756,7 +756,7 @@ bool MainWindow::createEventRoleWidget() {
eventRoleWidget->setChannelMap(cm, true);
eventRoleWidget->boldNameLabel->setText(QLatin1String(""));
- eventRoleWidget->nameLabel->setText(tr("System Sounds").toUtf8().constData());
+ eventRoleWidget->nameLabel->setText(tr("System Sounds"));
setIconByName(eventRoleWidget->iconImage, "multimedia-volume-control");
diff --git a/src/pavucontrol.cc b/src/pavucontrol.cc
index 40f0c55..5456baa 100644
--- a/src/pavucontrol.cc
+++ b/src/pavucontrol.cc
@@ -653,11 +653,11 @@ int main(int argc, char *argv[]) {
QString locale = QLocale::system().name();
QTranslator qtTranslator;
- if(qtTranslator.load("qt_" + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
+ if(qtTranslator.load(QStringLiteral("qt_") + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
qApp->installTranslator(&qtTranslator);
QTranslator appTranslator;
- if(appTranslator.load("pavucontrol-qt_" + locale, PAVUCONTROL_QT_DATA_DIR "/translations"))
+ if(appTranslator.load(QStringLiteral("pavucontrol-qt_") + locale, QStringLiteral(PAVUCONTROL_QT_DATA_DIR) + QStringLiteral("/translations")))
qApp->installTranslator(&appTranslator);
QCommandLineParser parser;
diff --git a/src/rolewidget.cc b/src/rolewidget.cc
index a37fb48..fa415e9 100644
--- a/src/rolewidget.cc
+++ b/src/rolewidget.cc
@@ -47,7 +47,7 @@ void RoleWidget::executeVolumeUpdate() {
if (updating)
return;
- info.name = role;
+ info.name = role.constData();
info.channel_map.channels = 1;
info.channel_map.map[0] = PA_CHANNEL_POSITION_MONO;
info.volume = volume;
diff --git a/src/sinkinputwidget.cc b/src/sinkinputwidget.cc
index bda7028..81a52e9 100644
--- a/src/sinkinputwidget.cc
+++ b/src/sinkinputwidget.cc
@@ -47,10 +47,10 @@ void SinkInputWidget::setSinkIndex(uint32_t idx) {
if (mpMainWindow->sinkWidgets.count(idx)) {
SinkWidget *w = mpMainWindow->sinkWidgets[idx];
- deviceButton->setText(w->description);
+ deviceButton->setText(QString::fromUtf8(w->description));
}
else
- deviceButton->setText(tr("Unknown output").toUtf8().constData());
+ deviceButton->setText(tr("Unknown output"));
}
uint32_t SinkInputWidget::sinkIndex() {
@@ -95,7 +95,7 @@ void SinkInputWidget::onKill() {
void SinkInputWidget::buildMenu() {
for (auto & sinkWidget : mpMainWindow->sinkWidgets) {
- menu->addAction(new SinkMenuItem{this, sinkWidget.second->description, sinkWidget.second->index, sinkWidget.second->index == mSinkIndex, menu});
+ menu->addAction(new SinkMenuItem{this, sinkWidget.second->description.constData(), sinkWidget.second->index, sinkWidget.second->index == mSinkIndex, menu});
}
}
diff --git a/src/sinkinputwidget.h b/src/sinkinputwidget.h
index d92b963..fda790c 100644
--- a/src/sinkinputwidget.h
+++ b/src/sinkinputwidget.h
@@ -59,7 +59,7 @@ private:
, uint32_t i
, bool active
, QObject * parent = nullptr)
- : QAction(label, parent)
+ : QAction(QString::fromUtf8(label), parent)
, widget(w)
, index(i)
{
diff --git a/src/sinkwidget.cc b/src/sinkwidget.cc
index b4c6815..7bec630 100644
--- a/src/sinkwidget.cc
+++ b/src/sinkwidget.cc
@@ -106,7 +106,7 @@ void SinkWidget::onDefaultToggleButton() {
if (updating)
return;
- if (!(o = pa_context_set_default_sink(get_context(), name, nullptr, nullptr))) {
+ if (!(o = pa_context_set_default_sink(get_context(), name.constData(), nullptr, nullptr))) {
show_error(tr("pa_context_set_default_sink() failed").toUtf8().constData());
return;
}
diff --git a/src/sourceoutputwidget.cc b/src/sourceoutputwidget.cc
index 63494ed..3927dba 100644
--- a/src/sourceoutputwidget.cc
+++ b/src/sourceoutputwidget.cc
@@ -32,8 +32,8 @@ SourceOutputWidget::SourceOutputWidget(MainWindow *parent) :
menu{new QMenu{this}}
{
- gchar *txt;
- directionLabel->setText(txt = g_markup_printf_escaped("<i>%s</i>", tr("from").toUtf8().constData()));
+ gchar *txt = g_markup_printf_escaped("<i>%s</i>", tr("from").toUtf8().constData());
+ directionLabel->setText(QString::fromUtf8(static_cast<char*>(txt)));
g_free(txt);
terminate->setText(tr("Terminate Recording"));
@@ -54,10 +54,10 @@ void SourceOutputWidget::setSourceIndex(uint32_t idx) {
if (mpMainWindow->sourceWidgets.count(idx)) {
SourceWidget *w = mpMainWindow->sourceWidgets[idx];
- deviceButton->setText(w->description);
+ deviceButton->setText(QString::fromUtf8(w->description));
}
else
- deviceButton->setText(tr("Unknown input").toUtf8().constData());
+ deviceButton->setText(tr("Unknown input"));
}
uint32_t SourceOutputWidget::sourceIndex() {
@@ -105,7 +105,7 @@ void SourceOutputWidget::onKill() {
void SourceOutputWidget::buildMenu() {
for (auto & sourceWidget : mpMainWindow->sourceWidgets) {
- menu->addAction(new SourceMenuItem{this, sourceWidget.second->description, sourceWidget.second->index, sourceWidget.second->index == mSourceIndex, menu});
+ menu->addAction(new SourceMenuItem{this, sourceWidget.second->description.constData(), sourceWidget.second->index, sourceWidget.second->index == mSourceIndex, menu});
}
}
diff --git a/src/sourceoutputwidget.h b/src/sourceoutputwidget.h
index a0ed95e..d30f83a 100644
--- a/src/sourceoutputwidget.h
+++ b/src/sourceoutputwidget.h
@@ -62,7 +62,7 @@ private:
, uint32_t i
, bool active
, QObject * parent = nullptr)
- : QAction{label, parent}
+ : QAction{QString::fromUtf8(label), parent}
, widget(w)
, index(i)
{
diff --git a/src/sourcewidget.cc b/src/sourcewidget.cc
index a2f4427..cecd893 100644
--- a/src/sourcewidget.cc
+++ b/src/sourcewidget.cc
@@ -60,7 +60,7 @@ void SourceWidget::onDefaultToggleButton() {
if (updating)
return;
- if (!(o = pa_context_set_default_source(get_context(), name, nullptr, nullptr))) {
+ if (!(o = pa_context_set_default_source(get_context(), name.constData(), nullptr, nullptr))) {
show_error(tr("pa_context_set_default_source() failed").toUtf8().constData());
return;
}