Commit de0e1bc1 authored by Andras Mantia's avatar Andras Mantia
Browse files

Use QUrl in the ScreenMapper API

Reviewers: #plasma, mwolff, broulik, hein

Reviewed By: #plasma, mwolff, hein

Subscribers: ervin, mlaurent, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D9325
parent f51036f4
......@@ -31,6 +31,11 @@ QTEST_MAIN(FolderModelTest)
static const QLatin1String desktop(QLatin1String("Desktop"));
static QUrl stringToUrl(const QString &path)
{
return QUrl::fromUserInput(path, {}, QUrl::AssumeLocalFile);
}
void FolderModelTest::createTestFolder(const QString &path)
{
QDir dir(m_folderDir->path());
......@@ -268,28 +273,29 @@ void FolderModelTest::tst_lockedChanged()
void FolderModelTest::tst_multiScreen()
{
delete m_folderModel;
// Custom instance for this test to set screen mapper before marking component
// Custom instance for this test to set used by containment before marking component
// as complete.
m_folderModel = new FolderModel(this);
m_folderModel->classBegin();
m_folderModel->setUrl(m_folderDir->path() + QDir::separator() + desktop );
auto *screenMapper = ScreenMapper::instance();
m_folderModel->setUsedByContainment(true);
m_folderModel->setScreen(0);
m_folderModel->componentComplete();
auto *screenMapper = ScreenMapper::instance();
QSignalSpy s(m_folderModel, &FolderModel::listingCompleted);
s.wait(1000);
QVERIFY(s.wait(1000));
const auto count = m_folderModel->rowCount();
for (int i = 0; i < count; i++) {
const auto index = m_folderModel->index(i, 0);
const auto name = index.data(FolderModel::UrlRole).toString();
const auto name = index.data(FolderModel::UrlRole).toUrl();
// all items are on the first screen by default
QCOMPARE(screenMapper->screenForItem(name), 0);
}
// move one file to a new screen
const auto movedItem = m_folderModel->index(0, 0).data(FolderModel::UrlRole).toString();
const auto movedItem = m_folderModel->index(0, 0).data(FolderModel::UrlRole).toUrl();
FolderModel secondFolderModel;
secondFolderModel.classBegin();
secondFolderModel.setUrl(m_folderDir->path() + QDir::separator() + desktop );
......@@ -297,7 +303,7 @@ void FolderModelTest::tst_multiScreen()
secondFolderModel.setScreen(1);
secondFolderModel.componentComplete();
QSignalSpy s2(&secondFolderModel, &FolderModel::listingCompleted);
s2.wait(1000);
QVERIFY(s2.wait(1000));
const auto count2 = secondFolderModel.rowCount();
QCOMPARE(count2, 0);
......@@ -309,23 +315,23 @@ void FolderModelTest::tst_multiScreen()
// we have one less item
QCOMPARE(m_folderModel->rowCount(), count - 1);
QCOMPARE(secondFolderModel.rowCount(), 1);
QCOMPARE(secondFolderModel.index(0,0).data(FolderModel::UrlRole).toString(), movedItem);
QCOMPARE(secondFolderModel.index(0,0).data(FolderModel::UrlRole).toUrl(), movedItem);
QCOMPARE(screenMapper->screenForItem(movedItem), 1);
// remove extra screen, we have all items back
screenMapper->removeScreen(1, m_folderModel->url());
screenMapper->removeScreen(1, stringToUrl(m_folderModel->url()));
s.wait(500);
QCOMPARE(m_folderModel->rowCount(), count);
QCOMPARE(secondFolderModel.rowCount(), 0);
QCOMPARE(screenMapper->screenForItem(movedItem), 0);
// add back extra screen, the item is moved there
screenMapper->addScreen(1, m_folderModel->url());
screenMapper->addScreen(1, stringToUrl(m_folderModel->url()));
s.wait(500);
s2.wait(500);
QCOMPARE(m_folderModel->rowCount(), count - 1);
QCOMPARE(secondFolderModel.rowCount(), 1);
QCOMPARE(secondFolderModel.index(0,0).data(FolderModel::UrlRole).toString(), movedItem);
QCOMPARE(secondFolderModel.index(0,0).data(FolderModel::UrlRole).toUrl(), movedItem);
QCOMPARE(screenMapper->screenForItem(movedItem), 1);
// create a new item, it appears on the first screen
......@@ -336,7 +342,7 @@ void FolderModelTest::tst_multiScreen()
s.wait(1000);
QCOMPARE(m_folderModel->rowCount(), count);
QCOMPARE(secondFolderModel.rowCount(), 1);
QCOMPARE(screenMapper->screenForItem("file://" + dir.path()), 0);
QCOMPARE(screenMapper->screenForItem(stringToUrl("file://" + dir.path())), 0);
}
void FolderModelTest::tst_multiScreenDifferenPath()
......
......@@ -270,7 +270,7 @@ void PositionerTest::tst_proxyMapping()
verifyMapping(secondPositioner.proxyToSourceMapping(), expectedProxy2SourceScreen1);
verifyMapping(secondPositioner.sourceToProxyMapping(), expectedSource2ProxyScreen1);
const auto movedItem = m_folderModel->index(1, 0).data(FolderModel::UrlRole).toString();
const auto movedItem = m_folderModel->index(1, 0).data(FolderModel::UrlRole).toUrl();
// move the item 1 from source (now in position 2) to the second screen
screenMapper->addMapping(movedItem, 1);
......
......@@ -40,7 +40,7 @@ void ScreenMapperTest::init()
void ScreenMapperTest::tst_addScreens()
{
const auto path = QStringLiteral("desktop:/");
const auto path = ScreenMapper::stringToUrl(QStringLiteral("desktop:/"));
QSignalSpy s(m_screenMapper, &ScreenMapper::screensChanged);
m_screenMapper->addScreen(-1, path);
QCOMPARE(s.count(), 0);
......@@ -55,7 +55,7 @@ void ScreenMapperTest::tst_addScreens()
void ScreenMapperTest::tst_removeScreens()
{
const auto path = QStringLiteral("desktop:/");
const auto path = ScreenMapper::stringToUrl(QStringLiteral("desktop:/"));
addScreens(path);
QSignalSpy s(m_screenMapper, &ScreenMapper::screensChanged);
m_screenMapper->removeScreen(-1, path);
......@@ -74,41 +74,41 @@ void ScreenMapperTest::tst_removeScreens()
void ScreenMapperTest::tst_addMapping()
{
const auto path = QStringLiteral("desktop:/");
const auto path = ScreenMapper::stringToUrl(QStringLiteral("desktop:/"));
addScreens(path);
QSignalSpy s(m_screenMapper, &ScreenMapper::screenMappingChanged);
QString file("desktop:/foo%1.txt");
for (int i = 0 ; i < 3; i++) {
const QString name = file.arg(i);
m_screenMapper->addMapping(name, i);
const QUrl url = ScreenMapper::stringToUrl(file.arg(i));
m_screenMapper->addMapping(url, i);
QCOMPARE(s.count(), i + 1);
QCOMPARE(m_screenMapper->screenForItem(name), i);
QCOMPARE(m_screenMapper->screenForItem(url), i);
}
}
void ScreenMapperTest::tst_addRemoveScreenWithItems()
{
const auto path = QStringLiteral("desktop:/");
const auto path = ScreenMapper::stringToUrl(QStringLiteral("desktop:/"));
addScreens(path);
QString file("desktop:/foo%1.txt");
for (int i = 0 ; i < 3; i++) {
const QString name = file.arg(i);
m_screenMapper->addMapping(name, i);
const QUrl url = ScreenMapper::stringToUrl(file.arg(i));
m_screenMapper->addMapping(url, i);
}
// remove one screen
m_screenMapper->removeScreen(1, path);
QCOMPARE(m_screenMapper->screenForItem(file.arg(0)), 0);
QCOMPARE(m_screenMapper->screenForItem(file.arg(1)), -1);
QCOMPARE(m_screenMapper->screenForItem(file.arg(2)), 2);
QCOMPARE(m_screenMapper->screenForItem(ScreenMapper::stringToUrl(file.arg(0))), 0);
QCOMPARE(m_screenMapper->screenForItem(ScreenMapper::stringToUrl(file.arg(1))), -1);
QCOMPARE(m_screenMapper->screenForItem(ScreenMapper::stringToUrl(file.arg(2))), 2);
// add removed screen back, items screen is restored
m_screenMapper->addScreen(1, path);
QCOMPARE(m_screenMapper->screenForItem(file.arg(0)), 0);
QCOMPARE(m_screenMapper->screenForItem(file.arg(1)), 1);
QCOMPARE(m_screenMapper->screenForItem(file.arg(2)), 2);
QCOMPARE(m_screenMapper->screenForItem(ScreenMapper::stringToUrl(file.arg(0))), 0);
QCOMPARE(m_screenMapper->screenForItem(ScreenMapper::stringToUrl(file.arg(1))), 1);
QCOMPARE(m_screenMapper->screenForItem(ScreenMapper::stringToUrl(file.arg(2))), 2);
// remove all screens, firstAvailableScreen changes
m_screenMapper->removeScreen(0, path);
......@@ -119,18 +119,18 @@ void ScreenMapperTest::tst_addRemoveScreenWithItems()
QCOMPARE(m_screenMapper->firstAvailableScreen(path), -1);
QCOMPARE(m_screenMapper->screenForItem(file.arg(0)), -1);
QCOMPARE(m_screenMapper->screenForItem(file.arg(1)), -1);
QCOMPARE(m_screenMapper->screenForItem(file.arg(2)), -1);
QCOMPARE(m_screenMapper->screenForItem(ScreenMapper::stringToUrl(file.arg(0))), -1);
QCOMPARE(m_screenMapper->screenForItem(ScreenMapper::stringToUrl(file.arg(1))), -1);
QCOMPARE(m_screenMapper->screenForItem(ScreenMapper::stringToUrl(file.arg(2))), -1);
// add all screens back, all item's screen is restored
addScreens(path);
QCOMPARE(m_screenMapper->screenForItem(file.arg(0)), 0);
QCOMPARE(m_screenMapper->screenForItem(file.arg(1)), 1);
QCOMPARE(m_screenMapper->screenForItem(file.arg(2)), 2);
QCOMPARE(m_screenMapper->screenForItem(ScreenMapper::stringToUrl(file.arg(0))), 0);
QCOMPARE(m_screenMapper->screenForItem(ScreenMapper::stringToUrl(file.arg(1))), 1);
QCOMPARE(m_screenMapper->screenForItem(ScreenMapper::stringToUrl(file.arg(2))), 2);
// remove one screen and move its item
const QString movedItem = file.arg(1);
const QUrl movedItem = ScreenMapper::stringToUrl(file.arg(1));
m_screenMapper->removeScreen(1, path);
QCOMPARE(m_screenMapper->screenForItem(movedItem), -1);
m_screenMapper->addMapping(movedItem, 0);
......@@ -143,15 +143,15 @@ void ScreenMapperTest::tst_addRemoveScreenWithItems()
void ScreenMapperTest::tst_addRemoveScreenDifferentPaths()
{
const auto path = QStringLiteral("desktop:/Foo");
const auto path2 = QStringLiteral("desktop:/Foo2");
const auto path = ScreenMapper::stringToUrl(QStringLiteral("desktop:/Foo"));
const auto path2 = ScreenMapper::stringToUrl(QStringLiteral("desktop:/Foo2"));
m_screenMapper->addScreen(0, path);
QCOMPARE(m_screenMapper->firstAvailableScreen(path), 0);
QCOMPARE(m_screenMapper->firstAvailableScreen(path2), -1);
}
void ScreenMapperTest::addScreens(const QString &path)
void ScreenMapperTest::addScreens(const QUrl &path)
{
m_screenMapper->addScreen(0, path);
m_screenMapper->addScreen(1, path);
......
......@@ -42,7 +42,7 @@ private Q_SLOTS:
void tst_addRemoveScreenDifferentPaths();
private:
void addScreens(const QString &path);
void addScreens(const QUrl &path);
ScreenMapper *m_screenMapper;
};
......
......@@ -208,7 +208,7 @@ FolderModel::~FolderModel()
// disconnect so we don't handle signals from the screen mapper when
// removeScreen is called
m_screenMapper->disconnect(this);
m_screenMapper->removeScreen(m_screen, url());
m_screenMapper->removeScreen(m_screen, resolvedUrl());
}
}
......@@ -267,7 +267,7 @@ void FolderModel::invalidateFilterIfComplete()
void FolderModel::newFileMenuItemCreated(const QUrl &url)
{
if (m_usedByContainment) {
m_screenMapper->addMapping(url.toString(), m_screen, ScreenMapper::DelayedSignal);
m_screenMapper->addMapping(url, m_screen, ScreenMapper::DelayedSignal);
m_dropTargetPositions.insert(url.fileName(), m_menuPosition);
m_menuPosition = {};
m_dropTargetPositionsCleanup->start();
......@@ -281,19 +281,19 @@ QString FolderModel::url() const
void FolderModel::setUrl(const QString& url)
{
const QUrl &resolvedUrl = resolve(url);
const QUrl &resolvedNewUrl = resolve(url);
if (url == m_url) {
m_dirModel->dirLister()->updateDirectory(resolvedUrl);
m_dirModel->dirLister()->updateDirectory(resolvedNewUrl);
return;
}
const auto oldUrl = m_url;
const auto oldUrl = resolvedUrl();
beginResetModel();
m_url = url;
m_isDirCache.clear();
m_dirModel->dirLister()->openUrl(resolvedUrl);
m_dirModel->dirLister()->openUrl(resolvedNewUrl);
clearDragImages();
m_dragIndexes.clear();
endResetModel();
......@@ -309,11 +309,11 @@ void FolderModel::setUrl(const QString& url)
m_dirWatch = nullptr;
}
if (resolvedUrl.isValid()) {
if (resolvedNewUrl.isValid()) {
m_dirWatch = new KDirWatch(this);
connect(m_dirWatch, &KDirWatch::created, this, &FolderModel::iconNameChanged);
connect(m_dirWatch, &KDirWatch::dirty, this, &FolderModel::iconNameChanged);
m_dirWatch->addFile(resolvedUrl.toLocalFile() + QLatin1String("/.directory"));
m_dirWatch->addFile(resolvedNewUrl.toLocalFile() + QLatin1String("/.directory"));
}
if (m_dragInProgress) {
......@@ -324,7 +324,7 @@ void FolderModel::setUrl(const QString& url)
if (m_usedByContainment) {
m_screenMapper->removeScreen(m_screen, oldUrl);
m_screenMapper->addScreen(m_screen, url);
m_screenMapper->addScreen(m_screen, resolvedUrl());
}
}
......@@ -630,7 +630,7 @@ void FolderModel::setScreen(int screen)
m_screen = screen;
if (m_usedByContainment) {
m_screenMapper->addScreen(screen, url());
m_screenMapper->addScreen(screen, resolvedUrl());
}
emit screenChanged();
}
......@@ -1059,16 +1059,17 @@ void FolderModel::drop(QQuickItem *target, QObject* dropEvent, int row)
* use a fancy scheme like desktop:/ instead. Ensure we always use the latter to properly map URLs,
* i.e. go from file:///home/user/Desktop/file to desktop:/file
*/
auto mappableUrl = [this, dropTargetFolderUrl](const QUrl &url) -> QString {
QString mappedUrl = url.toString();
auto mappableUrl = [this, dropTargetFolderUrl](const QUrl &url) -> QUrl {
if (dropTargetFolderUrl != m_dirModel->dirLister()->url()) {
QString mappedUrl = url.toString();
const auto local = dropTargetFolderUrl.toString();
const auto internal = m_dirModel->dirLister()->url().toString();
if (mappedUrl.startsWith(local)) {
mappedUrl.replace(0, local.size(), internal);
}
return ScreenMapper::stringToUrl(mappedUrl);
}
return mappedUrl;
return url;
};
const int x = dropEvent->property("x").toInt();
......@@ -1166,10 +1167,10 @@ void FolderModel::drop(QQuickItem *target, QObject* dropEvent, int row)
if (m_usedByContainment) {
// assign a screen for the item before the copy is actually done, so
// filterAcceptsRow doesn't assign the default screen to it
QUrl url = QUrl::fromUserInput(m_url, {}, QUrl::AssumeLocalFile);
QUrl url = resolvedUrl();
// if the folderview's folder is a standard path, just use the targetUrl for mapping
if (targetUrl.toString().startsWith(url.toString())) {
m_screenMapper->addMapping(targetUrl.toString(), m_screen, ScreenMapper::DelayedSignal);
m_screenMapper->addMapping(targetUrl, m_screen, ScreenMapper::DelayedSignal);
} else if (targetUrl.toString().startsWith(dropTargetUrl.toString())) {
// if the folderview's folder is a special path, like desktop:// , we need to convert
// the targetUrl file:// path to a desktop:/ path for mapping
......@@ -1177,7 +1178,7 @@ void FolderModel::drop(QQuickItem *target, QObject* dropEvent, int row)
auto filePath = targetUrl.path();
if (filePath.startsWith(destPath)) {
url.setPath(filePath.remove(0, destPath.length()));
m_screenMapper->addMapping(url.toString(), m_screen, ScreenMapper::DelayedSignal);
m_screenMapper->addMapping(url, m_screen, ScreenMapper::DelayedSignal);
}
}
}
......@@ -1372,7 +1373,7 @@ void FolderModel::statResult(KJob *job)
void FolderModel::evictFromIsDirCache(const KFileItemList& items)
{
foreach (const KFileItem &item, items) {
m_screenMapper->removeFromMap(item.url().toString());
m_screenMapper->removeFromMap(item.url());
m_isDirCache.remove(item.url());
}
}
......@@ -1498,16 +1499,16 @@ bool FolderModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParen
const KFileItem item = dirModel->itemForIndex(dirModel->index(sourceRow, KDirModel::Name, sourceParent));
if (m_usedByContainment) {
const QString name = item.url().toString();
const int screen = m_screenMapper->screenForItem(name);
const QUrl url = item.url();
const int screen = m_screenMapper->screenForItem(url);
// don't do anything if the folderview is not associated with a screen
if (m_screen != -1) {
if (screen == -1) {
// The item is not associated with a screen, probably because this is the first
// time we see it or the folderview was previously used as a regular applet.
// Associated with this folderview if the view is on the first available screen
if (m_screen == m_screenMapper->firstAvailableScreen(url())) {
m_screenMapper->addMapping(name, m_screen, ScreenMapper::DelayedSignal);
if (m_screen == m_screenMapper->firstAvailableScreen(resolvedUrl())) {
m_screenMapper->addMapping(url, m_screen, ScreenMapper::DelayedSignal);
} else {
return false;
}
......@@ -1963,3 +1964,4 @@ void FolderModel::undoTextChanged(const QString &text)
action->setText(text);
}
}
......@@ -58,18 +58,17 @@ ScreenMapper::ScreenMapper(QObject *parent)
m_screenMappingChangedTimer->setSingleShot(true);
}
void ScreenMapper::removeScreen(int screenId, const QString &path)
void ScreenMapper::removeScreen(int screenId, const QUrl &screenUrl)
{
if (screenId < 0 || !m_availableScreens.contains(screenId))
return;
QUrl screenUrl = QUrl::fromUserInput(path, {}, QUrl::AssumeLocalFile);
const auto screenPathWithScheme = screenUrl.url();
// store the original location for the items
auto it = m_screenItemMap.constBegin();
while (it != m_screenItemMap.constEnd()) {
const auto name = it.key();
if (it.value() == screenId && name.startsWith(screenPathWithScheme)) {
if (it.value() == screenId && name.url().startsWith(screenPathWithScheme)) {
m_itemsOnDisabledScreensMap[screenId].append(name);
}
++it;
......@@ -78,14 +77,14 @@ void ScreenMapper::removeScreen(int screenId, const QString &path)
m_availableScreens.removeAll(screenId);
const auto newFirstScreen = std::min_element(m_availableScreens.constBegin(), m_availableScreens.constEnd());
auto pathIt = m_screensPerPath.find(path);
auto pathIt = m_screensPerPath.find(screenUrl);
if (pathIt != m_screensPerPath.end() && pathIt.value() > 0) {
int firstScreen = m_firstScreenForPath.value(path, -1);
int firstScreen = m_firstScreenForPath.value(screenUrl, -1);
if (firstScreen == screenId) {
m_firstScreenForPath[path] = (newFirstScreen == m_availableScreens.constEnd()) ? -1 : *newFirstScreen;
m_firstScreenForPath[screenUrl] = (newFirstScreen == m_availableScreens.constEnd()) ? -1 : *newFirstScreen;
}
*pathIt = pathIt.value() - 1;
} else if (path.isEmpty()) {
} else if (screenUrl.isEmpty()) {
// The screen got completely removed, not only its path changed.
// If the removed screen was the first screen for a desktop path, the first screen for that path
// needs to be updated.
......@@ -105,14 +104,13 @@ void ScreenMapper::removeScreen(int screenId, const QString &path)
emit screensChanged();
}
void ScreenMapper::addScreen(int screenId, const QString &path)
void ScreenMapper::addScreen(int screenId, const QUrl &screenUrl)
{
if (screenId < 0 || m_availableScreens.contains(screenId))
return;
QUrl screenUrl = QUrl::fromUserInput(path, {}, QUrl::AssumeLocalFile);
const auto screenPathWithScheme = screenUrl.url();
const bool isEmpty = (path.isEmpty() || screenUrl.path() == "/");
const bool isEmpty = (screenUrl.isEmpty() || screenUrl.path() == QLatin1String("/"));
// restore the stored locations
auto it = m_itemsOnDisabledScreensMap.find(screenId);
if (it != m_itemsOnDisabledScreensMap.end()) {
......@@ -120,7 +118,7 @@ void ScreenMapper::addScreen(int screenId, const QString &path)
for (const auto &name: it.value()) {
// add the items to the new screen, if they are on a disabled screen and their
// location is below the new screen's path
if (isEmpty || name.startsWith(screenPathWithScheme)) {
if (isEmpty || name.url().startsWith(screenPathWithScheme)) {
addMapping(name, screenId, DelayedSignal);
items.removeAll(name);
}
......@@ -135,14 +133,14 @@ void ScreenMapper::addScreen(int screenId, const QString &path)
m_availableScreens.append(screenId);
// path is empty when a new screen appears that has no folderview base path associated with
if (!path.isEmpty()) {
auto it = m_screensPerPath.find(path);
int firstScreen = m_firstScreenForPath.value(path, -1);
if (!screenUrl.isEmpty()) {
auto it = m_screensPerPath.find(screenUrl);
int firstScreen = m_firstScreenForPath.value(screenUrl, -1);
if (firstScreen == -1 || screenId < firstScreen) {
m_firstScreenForPath[path] = screenId;
m_firstScreenForPath[screenUrl] = screenId;
}
if (it == m_screensPerPath.end()) {
m_screensPerPath[path] = 1;
m_screensPerPath[screenUrl] = 1;
} else {
*it = it.value() + 1;
}
......@@ -151,9 +149,9 @@ void ScreenMapper::addScreen(int screenId, const QString &path)
emit screensChanged();
}
void ScreenMapper::addMapping(const QString &name, int screen, MappingSignalBehavior behavior)
void ScreenMapper::addMapping(const QUrl &url, int screen, MappingSignalBehavior behavior)
{
m_screenItemMap[name] = screen;
m_screenItemMap[url] = screen;
if (behavior == DelayedSignal) {
m_screenMappingChangedTimer->start();
} else {
......@@ -161,23 +159,23 @@ void ScreenMapper::addMapping(const QString &name, int screen, MappingSignalBeha
}
}
void ScreenMapper::removeFromMap(const QString &name)
void ScreenMapper::removeFromMap(const QUrl &url)
{
m_screenItemMap.remove(name);
m_screenItemMap.remove(url);
m_screenMappingChangedTimer->start();
}
int ScreenMapper::firstAvailableScreen(const QString &path) const
int ScreenMapper::firstAvailableScreen(const QUrl &screenUrl) const
{
return m_firstScreenForPath.value(path, -1);
return m_firstScreenForPath.value(screenUrl, -1);
}
void ScreenMapper::removeItemFromDisabledScreen(const QString &name)
void ScreenMapper::removeItemFromDisabledScreen(const QUrl &url)
{
for (auto it = m_itemsOnDisabledScreensMap.begin();
it != m_itemsOnDisabledScreensMap.end(); ++it) {
auto names = &(*it);
names->removeAll(name);
auto urls = &(*it);
urls->removeAll(url);
}
}
......@@ -220,7 +218,7 @@ QStringList ScreenMapper::screenMapping() const
result.reserve(m_screenItemMap.count() * 2);
auto it = m_screenItemMap.constBegin();
while (it != m_screenItemMap.constEnd()) {
result.append(it.key());
result.append(it.key().toString());
result.append(QString::number(it.value()));
++it;
}
......@@ -230,12 +228,13 @@ QStringList ScreenMapper::screenMapping() const
void ScreenMapper::setScreenMapping(const QStringList &mapping)
{
QHash<QString, int> newMap;
QHash<QUrl, int> newMap;
const int count = mapping.count();
newMap.reserve(count / 2);
for (int i = 0; i < count - 1; i += 2) {
if (i + 1 < count) {
newMap[mapping[i]] = mapping[i + 1].toInt();
const QUrl url = QUrl::fromUserInput(mapping[i], {}, QUrl::AssumeLocalFile);
newMap[url] = mapping[i + 1].toInt();
}
}
......@@ -245,11 +244,16 @@ void ScreenMapper::setScreenMapping(const QStringList &mapping)
}
}
int ScreenMapper::screenForItem(const QString &name) const
int ScreenMapper::screenForItem(const QUrl &url) const
{
int screen = m_screenItemMap.value(name, -1);
int screen = m_screenItemMap.value(url, -1);
if (!m_availableScreens.contains(screen))
screen = -1;
return screen;
}
QUrl ScreenMapper::stringToUrl(const QString &path)
{
return QUrl::fromUserInput(path, {}, QUrl::AssumeLocalFile);
}
......@@ -50,20 +50,22 @@ public:
QStringList screenMapping() const;
void setScreenMapping(const QStringList &mapping);
int screenForItem(const QString &name) const;
void addMapping(const QString &name, int screen, MappingSignalBehavior behavior = ImmediateSignal);
void removeFromMap(const QString &name);
int screenForItem(const QUrl &url) const;
void addMapping(const QUrl &url, int screen, MappingSignalBehavior behavior = ImmediateSignal);
void removeFromMap(const QUrl &url);
void setCorona(Plasma::Corona *corona);
void addScreen(int screenId, const QString &path);
void removeScreen(int screenId, const QString &path);
int firstAvailableScreen(const QString &path) const;
void removeItemFromDisabledScreen(const QString &name);
void addScreen(int screenId, const QUrl &screenUrl);
void removeScreen(int screenId, const QUrl &screenUrl);
int firstAvailableScreen(const QUrl &screenUrl) const;
void removeItemFromDisabledScreen(const QUrl &url);
#ifdef BUILD_TESTING
void cleanup();
#endif