- QString name;
- if (url == QUrl("file:///")) {
- name = '/';
- } else {
- name = url.fileName();
- if (name.isEmpty()) {
- name = url.scheme();
- } else {
- // Make sure that a '&' inside the directory name is displayed correctly
- // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
- name.replace('&', "&&");
+ if (!tabPage) {
+ return QString();
+ }
+ QString name = tabPage->activeViewContainer()->caption();
+ // Make sure that a '&' inside the directory name is displayed correctly
+ // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
+ return name.replace('&', QLatin1String("&&"));
+}
+
+int DolphinTabWidget::getIndexByUrl(const QUrl& url) const
+{
+ for (int i = 0; i < count(); i++) {
+ // Conversion to display string is necessary to deal with the '~' alias.
+ // i.e. to acknowledge that ~/ is equivalent to /home/user/
+ const QUrl tabUrl = tabPageAt(i)->activeViewContainer()->url();
+ if (url == tabUrl ||
+ url.toDisplayString(QUrl::StripTrailingSlash) == tabUrl.toDisplayString(QUrl::StripTrailingSlash)) {
+ return i;