Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 85 additions & 31 deletions src/mumble/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,37 +1272,91 @@ void MainWindow::openUrl(const QUrl &url) {
* directly after server synchronization is completed.
* @see void MainWindow::msgServerSync(const MumbleProto::ServerSync &msg)
*/
void MainWindow::findDesiredChannel() {
bool found = false;
QStringList qlChans = qsDesiredChannel.split(QLatin1String("/"));
Channel *chan = Channel::get(Mumble::ROOT_CHANNEL_ID);
QString str = QString();
while (chan && qlChans.count() > 0) {
QString elem = qlChans.takeFirst().toLower();
if (elem.isEmpty())
continue;
if (str.isNull())
str = elem;
else
str = str + QLatin1String("/") + elem;
foreach (Channel *c, chan->qlChannels) {
if (c->qsName.toLower() == str) {
str = QString();
found = true;
chan = c;
break;
}
}
}
if (found) {
if (chan != ClientUser::get(Global::get().uiSession)->cChannel) {
Global::get().sh->joinChannel(Global::get().uiSession, chan->iId);
}
qtvUsers->setCurrentIndex(pmModel->index(chan));
} else if (Global::get().uiSession) {
qtvUsers->setCurrentIndex(pmModel->index(ClientUser::get(Global::get().uiSession)->cChannel));
}
updateMenuPermissions();
void MainWindow::findDesiredChannel() {
QStringList qlChans = qsDesiredChannel.split(QLatin1String("/"));
Channel *chan = Channel::get(Mumble::ROOT_CHANNEL_ID);
QString str = QString();

// Try case-sensitive search first (existing behavior)
bool found = findChannelWithSensitivity(chan, qlChans, str, true);

// If not found, try case-insensitive search
if (!found) {
// Reset for case-insensitive search
chan = Channel::get(Mumble::ROOT_CHANNEL_ID);
qlChans = qsDesiredChannel.split(QLatin1String("/"));
str = QString();

found = findChannelWithSensitivity(chan, qlChans, str, false);
}

if (found) {
if (chan != ClientUser::get(Global::get().uiSession)->cChannel) {
Global::get().sh->joinChannel(Global::get().uiSession, chan->iId);
}
qtvUsers->setCurrentIndex(pmModel->index(chan));
} else if (Global::get().uiSession) {
qtvUsers->setCurrentIndex(pmModel->index(ClientUser::get(Global::get().uiSession)->cChannel));
}

updateMenuPermissions();
}

// Helper method to find channel with either case-sensitive or case-insensitive search
bool MainWindow::findChannelWithSensitivity(Channel *&chan, QStringList &qlChans, QString &str, bool caseSensitive) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delegating the job to a separate function is perfectly fine and appreciated, however I would change the name to something more specific such as:

findChannelWithCasing()

while (chan && qlChans.count() > 0) {
QString elem = qlChans.takeFirst();

if (elem.isEmpty())
continue;

if (str.isNull())
str = elem;
else
str = str + QLatin1String("/") + elem;

if (caseSensitive) {
// Case-sensitive search
foreach (Channel *c, chan->qlChannels) {
if (c->qsName == str) {
str = QString();
chan = c;
return qlChans.isEmpty(); // Only return true if this was the last part
}
}
// If we get here, no match at this level - can't continue
return false;
} else {
// Case-insensitive search with ambiguity check
QList<Channel *> matches;

foreach (Channel *c, chan->qlChannels) {
if (c->qsName.compare(str, Qt::CaseInsensitive) == 0) {
matches.append(c);
}
}

if (matches.size() == 1) {
// Single match found - continue searching
str = QString();
chan = matches.first();

// Only return true if this was the last part
if (qlChans.isEmpty()) {
return true;
}
} else if (matches.size() > 1) {
// Multiple matches - ambiguous
qWarning() << "Ambiguous channel name:" << str;
return false;
} else {
// No matches
return false;
}
}
}

return false;
}

void MainWindow::setOnTop(bool top) {
Expand Down
Loading