]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Merge branch 'Applications/18.08'
authorElvis Angelaccio <elvis.angelaccio@kde.org>
Sun, 7 Oct 2018 17:53:08 +0000 (19:53 +0200)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Sun, 7 Oct 2018 17:53:08 +0000 (19:53 +0200)
1  2 
src/dolphinmainwindow.cpp
src/tests/dolphinmainwindowtest.cpp

index 8c76fe7809cd0eece4545ca175115b620574db36,38537d92a9edc4d52cf2e73a69398975c62383cd..7f36e82db08eab46355bc7b7346fbfab999a73c4
@@@ -25,6 -25,7 +25,6 @@@
  #include "dolphindockwidget.h"
  #include "dolphincontextmenu.h"
  #include "dolphinnewfilemenu.h"
 -#include "dolphinplacesmodelsingleton.h"
  #include "dolphinrecenttabsmenu.h"
  #include "dolphintabwidget.h"
  #include "dolphinviewcontainer.h"
@@@ -48,6 -49,7 +48,6 @@@
  #include <KAuthorized>
  #include <KConfig>
  #include <KFileItemListProperties>
 -#include <KFilePlacesModel>
  #include <KHelpMenu>
  #include <KIO/JobUiDelegate>
  #include <KIO/OpenFileManagerWindowJob>
@@@ -135,7 -137,7 +135,7 @@@ DolphinMainWindow::DolphinMainWindow() 
      connect(m_tabWidget, &DolphinTabWidget::tabCountChanged,
              this, &DolphinMainWindow::tabCountChanged);
      connect(m_tabWidget, &DolphinTabWidget::currentUrlChanged,
 -            this, &DolphinMainWindow::setUrlAsCaption);
 +            this, &DolphinMainWindow::updateWindowTitle);
      setCentralWidget(m_tabWidget);
  
      setupActions();
@@@ -455,10 -457,6 +455,6 @@@ void DolphinMainWindow::updateNewMenu(
      m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
      m_newFileMenu->checkUpToDate();
      m_newFileMenu->setPopupFiles(activeViewContainer()->url());
-     // If we're in the trash, also disable all the 'create new' items
-     // TODO: remove this once https://phabricator.kde.org/T8234 is implemented
-     slotWriteStateChanged(m_activeViewContainer->view()->url().scheme() != QLatin1String("trash"));
  }
  
  void DolphinMainWindow::createDirectory()
@@@ -590,7 -588,6 +586,7 @@@ void DolphinMainWindow::reloadView(
  {
      clearStatusBar();
      m_activeViewContainer->reload();
 +    m_activeViewContainer->statusBar()->updateSpaceInfo();
  }
  
  void DolphinMainWindow::stopLoading()
@@@ -807,10 -804,9 +803,9 @@@ void DolphinMainWindow::slotHandleUrlSt
  
  void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable)
  {
-     const auto actions = m_newFileMenu->menu()->actions();
-     for (auto menuItem : actions) {
-         menuItem->setEnabled(isFolderWritable);
-     }
+     // trash:/ is writable but we don't want to create new items in it.
+     // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
+     newFileMenu()->setEnabled(isFolderWritable && m_activeViewContainer->url().scheme() != QLatin1String("trash"));
  }
  
  void DolphinMainWindow::openContextMenu(const QPoint& pos,
@@@ -1000,9 -996,46 +995,9 @@@ void DolphinMainWindow::tabCountChanged
      actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions);
  }
  
 -void DolphinMainWindow::setUrlAsCaption(const QUrl& url)
 +void DolphinMainWindow::updateWindowTitle()
  {
 -    QString schemePrefix;
 -    if (!url.isLocalFile()) {
 -        schemePrefix.append(url.scheme() + " - ");
 -        if (!url.host().isEmpty()) {
 -            schemePrefix.append(url.host() + " - ");
 -        }
 -    }
 -
 -    if (GeneralSettings::showFullPathInTitlebar()) {
 -        const QString path = url.adjusted(QUrl::StripTrailingSlash).path();
 -        setWindowTitle(schemePrefix + path);
 -        return;
 -    }
 -
 -    KFilePlacesModel *placesModel = DolphinPlacesModelSingleton::instance().placesModel();
 -    const auto& matchedPlaces = placesModel->match(placesModel->index(0,0), KFilePlacesModel::UrlRole, url, 1, Qt::MatchExactly);
 -
 -    if (!matchedPlaces.isEmpty()) {
 -        setWindowTitle(placesModel->text(matchedPlaces.first()));
 -        return;
 -    }
 -
 -    QString fileName = url.adjusted(QUrl::StripTrailingSlash).fileName();
 -    if (fileName.isEmpty()) {
 -        fileName = '/';
 -    }
 -
 -    if (m_activeViewContainer->isSearchModeEnabled()) {
 -        if(m_activeViewContainer->currentSearchText().isEmpty()){
 -            setWindowTitle(i18n("Search"));
 -        } else {
 -            const auto searchText = i18n("Search for %1", m_activeViewContainer->currentSearchText());
 -            setWindowTitle(searchText);
 -        }
 -        return;
 -    }
 -
 -    setWindowTitle(schemePrefix + fileName);
 +    setWindowTitle(m_activeViewContainer->caption());
  }
  
  void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mountPath)
@@@ -1028,6 -1061,7 +1023,7 @@@ void DolphinMainWindow::setupActions(
  {
      // setup 'File' menu
      m_newFileMenu = new DolphinNewFileMenu(actionCollection(), this);
+     m_newFileMenu->setObjectName("newFileMenu");
      QMenu* menu = m_newFileMenu->menu();
      menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
      menu->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
@@@ -1228,8 -1262,6 +1224,8 @@@ void DolphinMainWindow::setupDockWidget
      infoDock->setLocked(lock);
      infoDock->setObjectName(QStringLiteral("infoDock"));
      infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
 +
 +#ifdef HAVE_BALOO
      InformationPanel* infoPanel = new InformationPanel(infoDock);
      infoPanel->setCustomContextMenuActions({lockLayoutAction});
      connect(infoPanel, &InformationPanel::urlActivated, this, &DolphinMainWindow::handleUrl);
              infoPanel, &InformationPanel::setSelection);
      connect(this, &DolphinMainWindow::requestItemInfo,
              infoPanel, &InformationPanel::requestDelayedItemInfo);
 +#endif
  
      // Setup "Folders"
      DolphinDockWidget* foldersDock = new DolphinDockWidget(i18nc("@title:window", "Folders"));
      panelsMenu->setDelayed(false);
      const KActionCollection* ac = actionCollection();
      panelsMenu->addAction(ac->action(QStringLiteral("show_places_panel")));
 +#ifdef HAVE_BALOO
      panelsMenu->addAction(ac->action(QStringLiteral("show_information_panel")));
 +#endif
      panelsMenu->addAction(ac->action(QStringLiteral("show_folders_panel")));
      panelsMenu->addAction(ac->action(QStringLiteral("show_terminal_panel")));
      panelsMenu->addSeparator();
@@@ -1468,7 -1497,7 +1464,7 @@@ void DolphinMainWindow::refreshViews(
          const bool splitView = GeneralSettings::splitView();
          m_tabWidget->currentTabPage()->setSplitViewEnabled(splitView);
          updateSplitAction();
 -        setUrlAsCaption(activeViewContainer()->url());
 +        updateWindowTitle();
      }
  
      emit settingsChanged();
index ca492215a0b3838bb2d222262584cf71670c414e,0dc33012418f3aba196f0848c28f8fb22ae51ddb..027ab3e891c78e0ef8cd6f241b340f4db145c80e
@@@ -18,6 -18,7 +18,7 @@@
   ***************************************************************************/
  
  #include "dolphinmainwindow.h"
+ #include "dolphinnewfilemenu.h"
  #include "dolphintabpage.h"
  #include "dolphintabwidget.h"
  #include "dolphinviewcontainer.h"
@@@ -39,8 -40,9 +40,11 @@@ private slots
      void testActiveViewAfterClosingSplitView_data();
      void testActiveViewAfterClosingSplitView();
      void testUpdateWindowTitleAfterClosingSplitView();
 +    void testOpenInNewTabTitle();
+     void testNewFileMenuEnabled_data();
+     void testNewFileMenuEnabled();
 +
  private:
      QScopedPointer<DolphinMainWindow> m_mainWindow;
  };
@@@ -171,23 -173,31 +175,48 @@@ void DolphinMainWindowTest::testUpdateW
      QCOMPARE(currentUrlChangedSpy.count(), 1);
  }
  
 +// Test case for bug #397910
 +void DolphinMainWindowTest::testOpenInNewTabTitle()
 +{
 +    m_mainWindow->openDirectories({ QUrl::fromLocalFile(QDir::homePath()) }, false);
 +    m_mainWindow->show();
 +    QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
 +    QVERIFY(m_mainWindow->isVisible());
 +
 +    auto tabWidget = m_mainWindow->findChild<DolphinTabWidget*>("tabWidget");
 +    QVERIFY(tabWidget);
 +
 +    tabWidget->openNewTab(QUrl::fromLocalFile(QDir::tempPath()));
 +    QCOMPARE(tabWidget->count(), 2);
 +    QVERIFY(tabWidget->tabIcon(0).name() != tabWidget->tabIcon(1).name());
 +    QVERIFY(tabWidget->tabText(0) != tabWidget->tabText(1));
 +}
 +
+ void DolphinMainWindowTest::testNewFileMenuEnabled_data()
+ {
+     QTest::addColumn<QUrl>("activeViewUrl");
+     QTest::addColumn<bool>("expectedEnabled");
+     QTest::newRow("home") << QUrl::fromLocalFile(QDir::homePath()) << true;
+     QTest::newRow("root") << QUrl::fromLocalFile(QDir::rootPath()) << false;
+     QTest::newRow("trash") << QUrl::fromUserInput(QStringLiteral("trash:/")) << false;
+ }
+ void DolphinMainWindowTest::testNewFileMenuEnabled()
+ {
+     QFETCH(QUrl, activeViewUrl);
+     m_mainWindow->openDirectories({ activeViewUrl }, false);
+     m_mainWindow->show();
+     QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
+     QVERIFY(m_mainWindow->isVisible());
+     auto newFileMenu = m_mainWindow->findChild<DolphinNewFileMenu*>("newFileMenu");
+     QVERIFY(newFileMenu);
+     QFETCH(bool, expectedEnabled);
+     QCOMPARE(newFileMenu->isEnabled(), expectedEnabled);
+ }
  QTEST_MAIN(DolphinMainWindowTest)
  
  #include "dolphinmainwindowtest.moc"