Merge branch 'release/20.12'

This commit is contained in:
Felix Ernst 2020-11-23 13:38:22 +01:00
commit b62095950a
4 changed files with 90 additions and 107 deletions

View file

@ -118,6 +118,10 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
m_urlNavigator.get(), &DolphinUrlNavigator::setLocationUrl);
connect(m_urlNavigator.get(), &DolphinUrlNavigator::urlChanged,
this, &DolphinViewContainer::slotUrlNavigatorLocationChanged);
connect(m_urlNavigator.get(), &DolphinUrlNavigator::urlAboutToBeChanged,
this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged);
connect(m_urlNavigator.get(), &DolphinUrlNavigator::urlSelectionRequested,
this, &DolphinViewContainer::slotUrlSelectionRequested);
connect(m_view, &DolphinView::writeStateChanged,
this, &DolphinViewContainer::writeStateChanged);
connect(m_view, &DolphinView::requestItemInfo,
@ -297,20 +301,18 @@ void DolphinViewContainer::connectUrlNavigator(DolphinUrlNavigator *urlNavigator
}
urlNavigator->setActive(isActive());
connect(m_view, &DolphinView::urlChanged,
urlNavigator, &DolphinUrlNavigator::setLocationUrl);
// Url changes are still done via m_urlNavigator.
connect(urlNavigator, &DolphinUrlNavigator::urlChanged,
this, &DolphinViewContainer::slotUrlNavigatorLocationChanged);
connect(urlNavigator, &DolphinUrlNavigator::activated,
this, &DolphinViewContainer::activate);
connect(urlNavigator, &DolphinUrlNavigator::urlAboutToBeChanged,
this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged);
connect(urlNavigator, &DolphinUrlNavigator::urlSelectionRequested,
this, &DolphinViewContainer::slotUrlSelectionRequested);
m_urlNavigator.get(), &DolphinUrlNavigator::setLocationUrl);
connect(urlNavigator, &DolphinUrlNavigator::urlsDropped,
this, [=](const QUrl &destination, QDropEvent *event) {
m_view->dropUrls(destination, event, urlNavigator->dropWidget());
});
// Aside from these, only visual things need to be connected.
connect(m_view, &DolphinView::urlChanged,
urlNavigator, &DolphinUrlNavigator::setLocationUrl);
connect(urlNavigator, &DolphinUrlNavigator::activated,
this, &DolphinViewContainer::activate);
m_urlNavigatorConnected = urlNavigator;
}
@ -321,18 +323,14 @@ void DolphinViewContainer::disconnectUrlNavigator()
return;
}
disconnect(m_view, &DolphinView::urlChanged,
m_urlNavigatorConnected, &DolphinUrlNavigator::setLocationUrl);
disconnect(m_urlNavigatorConnected, &DolphinUrlNavigator::urlChanged,
this, &DolphinViewContainer::slotUrlNavigatorLocationChanged);
disconnect(m_urlNavigatorConnected, &DolphinUrlNavigator::activated,
this, &DolphinViewContainer::activate);
disconnect(m_urlNavigatorConnected, &DolphinUrlNavigator::urlAboutToBeChanged,
this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged);
disconnect(m_urlNavigatorConnected, &DolphinUrlNavigator::urlSelectionRequested,
this, &DolphinViewContainer::slotUrlSelectionRequested);
m_urlNavigator.get(), &DolphinUrlNavigator::setLocationUrl);
disconnect(m_urlNavigatorConnected, &DolphinUrlNavigator::urlsDropped,
this, nullptr);
disconnect(m_view, &DolphinView::urlChanged,
m_urlNavigatorConnected, &DolphinUrlNavigator::setLocationUrl);
disconnect(m_urlNavigatorConnected, &DolphinUrlNavigator::activated,
this, &DolphinViewContainer::activate);
m_urlNavigatorVisualState = m_urlNavigatorConnected->visualState();
m_urlNavigatorConnected = nullptr;

View file

@ -77,7 +77,7 @@ bool PlacesPanel::urlChanged()
}
if (m_controller) {
selectClosestItem();
selectItem();
}
return true;
@ -139,7 +139,7 @@ void PlacesPanel::showEvent(QShowEvent* event)
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(container);
selectClosestItem();
selectItem();
}
Panel::showEvent(event);
@ -293,7 +293,7 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
}
}
selectClosestItem();
selectItem();
}
void PlacesPanel::slotViewContextMenuRequested(const QPointF& pos)
@ -361,7 +361,7 @@ void PlacesPanel::slotViewContextMenuRequested(const QPointF& pos)
}
}
selectClosestItem();
selectItem();
}
QAction *PlacesPanel::buildGroupContextMenu(QMenu *menu, int index)
@ -529,13 +529,17 @@ void PlacesPanel::editEntry(int index)
delete dialog;
}
void PlacesPanel::selectClosestItem()
void PlacesPanel::selectItem()
{
const int index = m_model->closestItem(url());
KItemListSelectionManager* selectionManager = m_controller->selectionManager();
selectionManager->setCurrentItem(index);
selectionManager->clearSelection();
selectionManager->setSelected(index);
const QUrl closestUrl = m_model->url(index);
if (!closestUrl.path().isEmpty() && url() == closestUrl) {
selectionManager->setSelected(index);
}
}
void PlacesPanel::triggerItem(int index, Qt::MouseButton button)

View file

@ -68,10 +68,10 @@ private:
void editEntry(int index);
/**
* Selects the item that has the closest URL for the URL set
* Selects the item that matches the URL set
* for the panel (see Panel::setUrl()).
*/
void selectClosestItem();
void selectItem();
void triggerItem(int index, Qt::MouseButton button);

View file

@ -71,6 +71,9 @@ private:
bool m_hasDesktopFolder = false;
bool m_hasDocumentsFolder = false;
bool m_hasDownloadsFolder = false;
bool m_hasMusicFolder = false;
bool m_hasPicturesFolder = false;
bool m_hasVideosFolder = false;
void setBalooEnabled(bool enabled);
int indexOf(const QUrl &url);
@ -82,6 +85,7 @@ private:
void schedulePlaceRemoval(int index);
void cancelPlaceRemoval(int index);
QMimeData *createMimeData(const QList<int> &indexes) const;
void increaseIndexIfNeeded(int &index) const;
QTemporaryDir m_tempHomeDir;
};
@ -161,6 +165,18 @@ QStringList PlacesItemModelTest::initialUrls() const
urls << QDir::homePath() + QStringLiteral("/Downloads");
}
if (m_hasMusicFolder) {
urls << QDir::homePath() + QStringLiteral("/Music");
}
if (m_hasPicturesFolder) {
urls << QDir::homePath() + QStringLiteral("/Pictures");
}
if (m_hasVideosFolder) {
urls << QDir::homePath() + QStringLiteral("/Videos");
}
urls << QStringLiteral("trash:/")
<< QStringLiteral("remote:/")
<< QStringLiteral("/media/nfs");
@ -215,6 +231,28 @@ QMimeData *PlacesItemModelTest::createMimeData(const QList<int> &indexes) const
return mimeData;
}
void PlacesItemModelTest::increaseIndexIfNeeded(int &index) const
{
if (m_hasDesktopFolder) {
index++;
}
if (m_hasDocumentsFolder) {
index++;
}
if (m_hasDownloadsFolder) {
index++;
}
if (m_hasMusicFolder) {
index++;
}
if (m_hasPicturesFolder) {
index++;
}
if (m_hasVideosFolder) {
index++;
}
}
void PlacesItemModelTest::init()
{
m_model = new PlacesItemModel();
@ -270,6 +308,21 @@ void PlacesItemModelTest::initTestCase()
m_expectedModelCount++;
}
if (QDir(QStandardPaths::writableLocation(QStandardPaths::MusicLocation)).exists()) {
m_hasMusicFolder = true;
m_expectedModelCount++;
}
if (QDir(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)).exists()) {
m_hasPicturesFolder = true;
m_expectedModelCount++;
}
if (QDir(QStandardPaths::writableLocation(QStandardPaths::MoviesLocation)).exists()) {
m_hasVideosFolder = true;
m_expectedModelCount++;
}
qRegisterMetaType<KItemRangeList>();
qRegisterMetaType<KItemRange>();
}
@ -289,15 +342,7 @@ void PlacesItemModelTest::testGroups()
{
const auto groups = m_model->groups();
int expectedRemoteIndex = 2;
if (m_hasDesktopFolder) {
expectedRemoteIndex++;
}
if (m_hasDocumentsFolder) {
expectedRemoteIndex++;
}
if (m_hasDownloadsFolder) {
expectedRemoteIndex++;
}
increaseIndexIfNeeded(expectedRemoteIndex);
QCOMPARE(groups.size(), 6);
@ -366,15 +411,7 @@ void PlacesItemModelTest::testDeletePlace()
PlacesItemModel *model = new PlacesItemModel();
int tempDirIndex = 2;
if (m_hasDesktopFolder) {
tempDirIndex++;
}
if (m_hasDocumentsFolder) {
tempDirIndex++;
}
if (m_hasDownloadsFolder) {
tempDirIndex++;
}
increaseIndexIfNeeded(tempDirIndex);
// create a new place
createPlaceItem(QStringLiteral("Temporary Dir"), tempUrl, QString());
@ -539,15 +576,7 @@ void PlacesItemModelTest::testHideItem()
void PlacesItemModelTest::testSystemItems()
{
int tempDirIndex = 2;
if (m_hasDesktopFolder) {
tempDirIndex++;
}
if (m_hasDocumentsFolder) {
tempDirIndex++;
}
if (m_hasDownloadsFolder) {
tempDirIndex++;
}
increaseIndexIfNeeded(tempDirIndex);
QCOMPARE(m_model->count(), m_expectedModelCount);
for (int r = 0; r < m_model->count(); r++) {
@ -590,15 +619,7 @@ void PlacesItemModelTest::testSystemItems()
void PlacesItemModelTest::testEditBookmark()
{
int tempDirIndex = 2;
if (m_hasDesktopFolder) {
tempDirIndex++;
}
if (m_hasDocumentsFolder) {
tempDirIndex++;
}
if (m_hasDownloadsFolder) {
tempDirIndex++;
}
increaseIndexIfNeeded(tempDirIndex);
QScopedPointer<PlacesItemModel> other(new PlacesItemModel());
@ -631,15 +652,7 @@ void PlacesItemModelTest::testEditBookmark()
void PlacesItemModelTest::testEditAfterCreation()
{
int tempDirIndex = 2;
if (m_hasDesktopFolder) {
tempDirIndex++;
}
if (m_hasDocumentsFolder) {
tempDirIndex++;
}
if (m_hasDownloadsFolder) {
tempDirIndex++;
}
increaseIndexIfNeeded(tempDirIndex);
const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
QSignalSpy itemsInsertedSpy(m_model, &PlacesItemModel::itemsInserted);
@ -671,15 +684,7 @@ void PlacesItemModelTest::testEditAfterCreation()
void PlacesItemModelTest::testEditMetadata()
{
int tempDirIndex = 2;
if (m_hasDesktopFolder) {
tempDirIndex++;
}
if (m_hasDocumentsFolder) {
tempDirIndex++;
}
if (m_hasDownloadsFolder) {
tempDirIndex++;
}
increaseIndexIfNeeded(tempDirIndex);
const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
QSignalSpy itemsInsertedSpy(m_model, &PlacesItemModel::itemsInserted);
@ -713,15 +718,7 @@ void PlacesItemModelTest::testEditMetadata()
void PlacesItemModelTest::testRefresh()
{
int tempDirIndex = 2;
if (m_hasDesktopFolder) {
tempDirIndex++;
}
if (m_hasDocumentsFolder) {
tempDirIndex++;
}
if (m_hasDownloadsFolder) {
tempDirIndex++;
}
increaseIndexIfNeeded(tempDirIndex);
const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
QSignalSpy itemsInsertedSpy(m_model, &PlacesItemModel::itemsInserted);
@ -784,15 +781,7 @@ void PlacesItemModelTest::testIcons()
void PlacesItemModelTest::testDragAndDrop()
{
int lastIndex = 1; // last index of places group
if (m_hasDesktopFolder) {
lastIndex++;
}
if (m_hasDocumentsFolder) {
lastIndex++;
}
if (m_hasDownloadsFolder) {
lastIndex++;
}
increaseIndexIfNeeded(lastIndex);
QList<QVariant> args;
KItemRangeList range;
@ -907,15 +896,7 @@ void PlacesItemModelTest::testDuplicatedEntries()
void PlacesItemModelTest::renameAfterCreation()
{
int tempDirIndex = 2;
if (m_hasDesktopFolder) {
tempDirIndex++;
}
if (m_hasDocumentsFolder) {
tempDirIndex++;
}
if (m_hasDownloadsFolder) {
tempDirIndex++;
}
increaseIndexIfNeeded(tempDirIndex);
const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
QStringList urls = initialUrls();