Changeset View
Changeset View
Standalone View
Standalone View
src/dolphintabwidget.cpp
Show All 13 Lines | |||||
14 | * You should have received a copy of the GNU General Public License * | 14 | * You should have received a copy of the GNU General Public License * | ||
15 | * along with this program; if not, write to the * | 15 | * along with this program; if not, write to the * | ||
16 | * Free Software Foundation, Inc., * | 16 | * Free Software Foundation, Inc., * | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | ||
18 | ***************************************************************************/ | 18 | ***************************************************************************/ | ||
19 | 19 | | |||
20 | #include "dolphintabwidget.h" | 20 | #include "dolphintabwidget.h" | ||
21 | 21 | | |||
22 | #include "dolphinmainwindow.h" | ||||
22 | #include "dolphintabbar.h" | 23 | #include "dolphintabbar.h" | ||
23 | #include "dolphintabpage.h" | 24 | #include "dolphintabpage.h" | ||
24 | #include "dolphinviewcontainer.h" | 25 | #include "dolphinviewcontainer.h" | ||
25 | 26 | | |||
26 | #include <KConfigGroup> | 27 | #include <KConfigGroup> | ||
27 | #include <KRun> | 28 | #include <KRun> | ||
28 | #include <KShell> | 29 | #include <KShell> | ||
29 | #include <kio/global.h> | 30 | #include <kio/global.h> | ||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Line(s) | 95 | { | |||
111 | const int index = group.readEntry("Active Tab Index", 0); | 112 | const int index = group.readEntry("Active Tab Index", 0); | ||
112 | setCurrentIndex(index); | 113 | setCurrentIndex(index); | ||
113 | } | 114 | } | ||
114 | 115 | | |||
115 | void DolphinTabWidget::refreshViews() | 116 | void DolphinTabWidget::refreshViews() | ||
116 | { | 117 | { | ||
117 | const int tabCount = count(); | 118 | const int tabCount = count(); | ||
118 | for (int i = 0; i < tabCount; ++i) { | 119 | for (int i = 0; i < tabCount; ++i) { | ||
120 | tabBar()->setTabText(i, tabName()); | ||||
119 | tabPageAt(i)->refreshViews(); | 121 | tabPageAt(i)->refreshViews(); | ||
120 | } | 122 | } | ||
121 | } | 123 | } | ||
122 | 124 | | |||
123 | void DolphinTabWidget::openNewActivatedTab() | 125 | void DolphinTabWidget::openNewActivatedTab() | ||
124 | { | 126 | { | ||
125 | const DolphinViewContainer* oldActiveViewContainer = currentTabPage()->activeViewContainer(); | 127 | const DolphinViewContainer* oldActiveViewContainer = currentTabPage()->activeViewContainer(); | ||
126 | Q_ASSERT(oldActiveViewContainer); | 128 | Q_ASSERT(oldActiveViewContainer); | ||
Show All 28 Lines | 156 | { | |||
155 | QWidget* focusWidget = QApplication::focusWidget(); | 157 | QWidget* focusWidget = QApplication::focusWidget(); | ||
156 | 158 | | |||
157 | DolphinTabPage* tabPage = new DolphinTabPage(primaryUrl, secondaryUrl, this); | 159 | DolphinTabPage* tabPage = new DolphinTabPage(primaryUrl, secondaryUrl, this); | ||
158 | tabPage->setPlacesSelectorVisible(m_placesSelectorVisible); | 160 | tabPage->setPlacesSelectorVisible(m_placesSelectorVisible); | ||
159 | connect(tabPage, &DolphinTabPage::activeViewChanged, | 161 | connect(tabPage, &DolphinTabPage::activeViewChanged, | ||
160 | this, &DolphinTabWidget::activeViewChanged); | 162 | this, &DolphinTabWidget::activeViewChanged); | ||
161 | connect(tabPage, &DolphinTabPage::activeViewUrlChanged, | 163 | connect(tabPage, &DolphinTabPage::activeViewUrlChanged, | ||
162 | this, &DolphinTabWidget::tabUrlChanged); | 164 | this, &DolphinTabWidget::tabUrlChanged); | ||
163 | addTab(tabPage, QIcon::fromTheme(KIO::iconNameForUrl(primaryUrl)), tabName(primaryUrl)); | 165 | addTab(tabPage, QIcon::fromTheme(KIO::iconNameForUrl(primaryUrl)), tabName()); | ||
164 | 166 | | |||
165 | if (focusWidget) { | 167 | if (focusWidget) { | ||
166 | // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened | 168 | // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened | ||
167 | // in background, assure that the previous focused widget gets the focus back. | 169 | // in background, assure that the previous focused widget gets the focus back. | ||
168 | focusWidget->setFocus(); | 170 | focusWidget->setFocus(); | ||
169 | } | 171 | } | ||
170 | } | 172 | } | ||
171 | 173 | | |||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | 300 | if (index >= 0) { | |||
300 | view->dropUrls(view->url(), event, view); | 302 | view->dropUrls(view->url(), event, view); | ||
301 | } | 303 | } | ||
302 | } | 304 | } | ||
303 | 305 | | |||
304 | void DolphinTabWidget::tabUrlChanged(const QUrl& url) | 306 | void DolphinTabWidget::tabUrlChanged(const QUrl& url) | ||
305 | { | 307 | { | ||
306 | const int index = indexOf(qobject_cast<QWidget*>(sender())); | 308 | const int index = indexOf(qobject_cast<QWidget*>(sender())); | ||
307 | if (index >= 0) { | 309 | if (index >= 0) { | ||
308 | tabBar()->setTabText(index, tabName(url)); | 310 | tabBar()->setTabText(index, tabName()); | ||
309 | tabBar()->setTabIcon(index, QIcon::fromTheme(KIO::iconNameForUrl(url))); | 311 | tabBar()->setTabIcon(index, QIcon::fromTheme(KIO::iconNameForUrl(url))); | ||
310 | 312 | | |||
311 | // Emit the currentUrlChanged signal if the url of the current tab has been changed. | 313 | // Emit the currentUrlChanged signal if the url of the current tab has been changed. | ||
312 | if (index == currentIndex()) { | 314 | if (index == currentIndex()) { | ||
313 | emit currentUrlChanged(url); | 315 | emit currentUrlChanged(url); | ||
314 | } | 316 | } | ||
315 | } | 317 | } | ||
316 | } | 318 | } | ||
Show All 31 Lines | 346 | { | |||
348 | // closing the last tab is not possible. | 350 | // closing the last tab is not possible. | ||
349 | if (count() < 2) { | 351 | if (count() < 2) { | ||
350 | tabBar()->hide(); | 352 | tabBar()->hide(); | ||
351 | } | 353 | } | ||
352 | 354 | | |||
353 | emit tabCountChanged(count()); | 355 | emit tabCountChanged(count()); | ||
354 | } | 356 | } | ||
355 | 357 | | |||
356 | QString DolphinTabWidget::tabName(const QUrl& url) const | 358 | QString DolphinTabWidget::tabName() const | ||
357 | { | 359 | { | ||
358 | QString name; | 360 | if (currentTabPage() == nullptr) { | ||
359 | if (url == QUrl(QStringLiteral("file:///"))) { | 361 | return QString(); | ||
360 | name = '/'; | 362 | } | ||
361 | } else { | 363 | QString name = currentTabPage()->activeViewContainer()->getCaption(); | ||
362 | name = url.adjusted(QUrl::StripTrailingSlash).fileName(); | | |||
363 | if (name.isEmpty()) { | | |||
364 | name = url.scheme(); | | |||
365 | } else { | | |||
366 | // Make sure that a '&' inside the directory name is displayed correctly | 364 | // Make sure that a '&' inside the directory name is displayed correctly | ||
367 | // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText() | 365 | // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText() | ||
368 | name.replace('&', QLatin1String("&&")); | 366 | return name.replace('&', QLatin1String("&&")); | ||
369 | } | | |||
370 | } | | |||
371 | return name; | | |||
372 | } | 367 | } |