summaryrefslogtreecommitdiffstats
path: root/src/mainwindow.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainwindow.cc')
-rw-r--r--src/mainwindow.cc72
1 files changed, 3 insertions, 69 deletions
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index 66c0ac4..0b6b310 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -36,17 +36,6 @@
#include <QStyle>
#include <QSettings>
-/* Used for profile sorting */
-struct profile_prio_compare {
- bool operator() (pa_card_profile_info2 const * const lhs, pa_card_profile_info2 const * const rhs) const {
-
- if (lhs->priority == rhs->priority)
- return strcmp(lhs->name, rhs->name) > 0;
-
- return lhs->priority > rhs->priority;
- }
-};
-
struct sink_port_prio_compare {
bool operator() (const pa_sink_port_info& lhs, const pa_sink_port_info& rhs) const {
@@ -211,6 +200,7 @@ void MainWindow::updateCard(const pa_card_info &info) {
setIconByName(w->iconImage, icon, "audio-card");
w->hasSinks = w->hasSources = false;
+
profile_priorities.clear();
for (pa_card_profile_info2 ** p_profile = info.profiles2; p_profile && *p_profile != nullptr; ++p_profile) {
w->hasSinks = w->hasSinks || ((*p_profile)->n_sinks > 0);
@@ -218,65 +208,9 @@ void MainWindow::updateCard(const pa_card_info &info) {
profile_priorities.insert(*p_profile);
}
- w->ports.clear();
- for (uint32_t i = 0; i < info.n_ports; ++i) {
- PortInfo p;
-
- p.name = info.ports[i]->name;
- p.description = info.ports[i]->description;
- p.priority = info.ports[i]->priority;
- p.available = info.ports[i]->available;
- p.direction = info.ports[i]->direction;
- p.latency_offset = info.ports[i]->latency_offset;
- for (pa_card_profile_info2 ** p_profile = info.ports[i]->profiles2; p_profile && *p_profile != nullptr; ++p_profile)
- p.profiles.push_back((*p_profile)->name);
-
- w->ports[p.name] = p;
- }
-
- w->profiles.clear();
- for (auto p_profile : profile_priorities) {
- bool hasNo = false, hasOther = false;
- std::map<QByteArray, PortInfo>::iterator portIt;
- QByteArray desc = p_profile->description;
-
- for (portIt = w->ports.begin(); portIt != w->ports.end(); portIt++) {
- PortInfo port = portIt->second;
+ populatePorts(info, w->ports);
- if (std::find(port.profiles.begin(), port.profiles.end(), p_profile->name) == port.profiles.end())
- continue;
-
- if (port.available == PA_PORT_AVAILABLE_NO)
- hasNo = true;
- else {
- hasOther = true;
- break;
- }
- }
- if (hasNo && !hasOther)
- desc += tr(" (unplugged)").toUtf8().constData();
-
- if (!p_profile->available)
- desc += tr(" (unavailable)").toUtf8().constData();
-
- QString parseId = QString::fromUtf8(p_profile->name);
- int plus = parseId.indexOf(QLatin1Char('+'));
- if (plus != -1) {
- parseId = parseId.left(plus);
- }
- auto list = parseId.split(QRegularExpression(QLatin1String("[:\\-]")));
- parseId.clear();
- for (auto p : list) {
- if (p == QLatin1String("input") || p == QLatin1String("output"))
- continue;
- if (parseId.isEmpty() || p.startsWith(QLatin1String("extra"))) {
- parseId.append(p);
- }
- }
- qDebug() << "ParseID:" << parseId;
- ProfileGroup &group = w->profiles[parseId];
- group.addEntry(p_profile->name, desc.constData());
- }
+ groupProfiles(profile_priorities, w->ports, w->profiles);
w->activeProfile = info.active_profile ? info.active_profile->name : "";