Commit 38268a14 authored by Andras Mantia's avatar Andras Mantia

Use ScreenMapper everywhere as a singleton

Summary:
There is no need to pass a ScreenMapper pointer around, as it is always the same,
it is a singleton.

Reviewers: #plasma, mwolff, hein

Reviewed By: mwolff

Subscribers: mlaurent, broulik, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D9323
parent 6fe81db8
......@@ -1080,7 +1080,6 @@ Item {
parseDesktopFiles: (plasmoid.configuration.url == "desktop:/")
previews: plasmoid.configuration.previews
previewPlugins: plasmoid.configuration.previewPlugins
screenMapper: Folder.ScreenMapper
appletInterface: plasmoid
onListingCompleted: {
......
......@@ -275,7 +275,6 @@ void FolderModelTest::tst_multiScreen()
m_folderModel->setUrl(m_folderDir->path() + QDir::separator() + desktop );
auto *screenMapper = ScreenMapper::instance();
m_folderModel->setUsedByContainment(true);
m_folderModel->setScreenMapper(screenMapper);
m_folderModel->setScreen(0);
m_folderModel->componentComplete();
......@@ -295,7 +294,6 @@ void FolderModelTest::tst_multiScreen()
secondFolderModel.classBegin();
secondFolderModel.setUrl(m_folderDir->path() + QDir::separator() + desktop );
secondFolderModel.setUsedByContainment(true);
secondFolderModel.setScreenMapper(screenMapper);
secondFolderModel.setScreen(1);
secondFolderModel.componentComplete();
QSignalSpy s2(&secondFolderModel, &FolderModel::listingCompleted);
......@@ -345,7 +343,6 @@ void FolderModelTest::tst_multiScreenDifferenPath()
{
auto *screenMapper = ScreenMapper::instance();
m_folderModel->setUsedByContainment(true);
m_folderModel->setScreenMapper(screenMapper);
m_folderModel->setScreen(0);
QSignalSpy s(m_folderModel, &FolderModel::listingCompleted);
s.wait(1000);
......@@ -356,7 +353,6 @@ void FolderModelTest::tst_multiScreenDifferenPath()
createTestFolder(desktop2);
FolderModel secondFolderModel;
secondFolderModel.setUsedByContainment(true);
secondFolderModel.setScreenMapper(screenMapper);
secondFolderModel.setUrl(m_folderDir->path() + QDir::separator() + desktop2 );
secondFolderModel.setScreen(1);
QSignalSpy s2(&secondFolderModel, &FolderModel::listingCompleted);
......
......@@ -61,7 +61,6 @@ void PositionerTest::init()
m_folderModel = new FolderModel(this);
m_folderModel->classBegin();
m_folderModel->setScreen(0);
m_folderModel->setScreenMapper(ScreenMapper::instance());
m_folderModel->setUsedByContainment(true);
m_folderModel->componentComplete();
m_positioner = new Positioner(this);
......@@ -222,7 +221,6 @@ void PositionerTest::tst_proxyMapping()
secondFolderModel.classBegin();
secondFolderModel.setUrl(m_folderDir->path() + QDir::separator() + desktop );
secondFolderModel.setUsedByContainment(true);
secondFolderModel.setScreenMapper(screenMapper);
secondFolderModel.setScreen(1);
secondFolderModel.componentComplete();
Positioner secondPositioner;
......
......@@ -120,7 +120,8 @@ FolderModel::FolderModel(QObject *parent) : QSortFilterProxyModel(parent),
m_previews(false),
m_filterMode(NoFilter),
m_filterPatternMatchAll(true),
m_complete(false)
m_complete(false),
m_screenMapper(ScreenMapper::instance())
{
//needed to pass the job around with qml
qmlRegisterType<KIO::DropJob>();
......@@ -203,7 +204,7 @@ FolderModel::FolderModel(QObject *parent) : QSortFilterProxyModel(parent),
FolderModel::~FolderModel()
{
if (m_screenMapper) {
if (m_usedByContainment) {
// disconnect so we don't handle signals from the screen mapper when
// removeScreen is called
m_screenMapper->disconnect(this);
......@@ -265,7 +266,7 @@ void FolderModel::invalidateFilterIfComplete()
void FolderModel::newFileMenuItemCreated(const QUrl &url)
{
if (m_screenMapper) {
if (m_usedByContainment) {
m_screenMapper->addMapping(url.toString(), m_screen, ScreenMapper::DelayedSignal);
m_dropTargetPositions.insert(url.fileName(), m_menuPosition);
m_menuPosition = {};
......@@ -321,7 +322,7 @@ void FolderModel::setUrl(const QString& url)
emit iconNameChanged();
if (m_screenMapper) {
if (m_usedByContainment) {
m_screenMapper->removeScreen(m_screen, oldUrl);
m_screenMapper->addScreen(m_screen, url);
}
......@@ -396,6 +397,10 @@ void FolderModel::setUsedByContainment(bool used)
action->setIcon(m_usedByContainment ? QIcon::fromTheme(QStringLiteral("user-desktop")) : QIcon::fromTheme(QStringLiteral("view-refresh")));
}
m_screenMapper->disconnect(this);
connect(m_screenMapper, &ScreenMapper::screensChanged, this, &FolderModel::invalidateFilterIfComplete);
connect(m_screenMapper, &ScreenMapper::screenMappingChanged, this, &FolderModel::invalidateFilterIfComplete);
emit usedByContainmentChanged();
}
}
......@@ -624,7 +629,7 @@ void FolderModel::setScreen(int screen)
return;
m_screen = screen;
if (m_usedByContainment && m_screenMapper) {
if (m_usedByContainment) {
m_screenMapper->addScreen(screen, url());
}
emit screenChanged();
......@@ -1111,12 +1116,10 @@ void FolderModel::drop(QQuickItem *target, QObject* dropEvent, int row)
if (m_usedByContainment) {
if (isDropBetweenSharedViews(mimeData->urls(), dropTargetFolderUrl)) {
setSortMode(-1);
if (m_screenMapper) {
for (const auto &url : mimeData->urls()) {
m_dropTargetPositions.insert(url.fileName(), dropPos);
m_screenMapper->addMapping(mappableUrl(url), m_screen, ScreenMapper::DelayedSignal);
m_screenMapper->removeItemFromDisabledScreen(mappableUrl(url));
}
for (const auto &url : mimeData->urls()) {
m_dropTargetPositions.insert(url.fileName(), dropPos);
m_screenMapper->addMapping(mappableUrl(url), m_screen, ScreenMapper::DelayedSignal);
m_screenMapper->removeItemFromDisabledScreen(mappableUrl(url));
}
m_dropTargetPositionsCleanup->start();
return;
......@@ -1160,7 +1163,7 @@ void FolderModel::drop(QQuickItem *target, QObject* dropEvent, int row)
m_dropTargetPositions.insert(targetUrl.fileName(), dropPos);
m_dropTargetPositionsCleanup->start();
if (m_usedByContainment && m_screenMapper) {
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);
......@@ -1369,9 +1372,7 @@ void FolderModel::statResult(KJob *job)
void FolderModel::evictFromIsDirCache(const KFileItemList& items)
{
foreach (const KFileItem &item, items) {
if (m_screenMapper) {
m_screenMapper->removeFromMap(item.url().toString());
}
m_screenMapper->removeFromMap(item.url().toString());
m_isDirCache.remove(item.url());
}
}
......@@ -1496,7 +1497,7 @@ bool FolderModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParen
const KDirModel *dirModel = static_cast<KDirModel*>(sourceModel());
const KFileItem item = dirModel->itemForIndex(dirModel->index(sourceRow, KDirModel::Name, sourceParent));
if (m_usedByContainment && m_screenMapper) {
if (m_usedByContainment) {
const QString name = item.url().toString();
const int screen = m_screenMapper->screenForItem(name);
// don't do anything if the folderview is not associated with a screen
......@@ -1853,32 +1854,6 @@ void FolderModel::refresh()
m_dirModel->dirLister()->updateDirectory(m_dirModel->dirLister()->url());
}
ScreenMapper *FolderModel::screenMapper() const
{
return m_screenMapper;
}
void FolderModel::setScreenMapper(ScreenMapper *screenMapper)
{
if (m_screenMapper == screenMapper)
return;
Q_ASSERT(!m_screenMapper);
if (m_screenMapper) {
m_screenMapper->disconnect(this);
}
m_screenMapper = screenMapper;
if (m_screenMapper) {
connect(m_screenMapper, &ScreenMapper::screensChanged, this, &FolderModel::invalidateFilterIfComplete);
connect(m_screenMapper, &ScreenMapper::screenMappingChanged, this, &FolderModel::invalidateFilterIfComplete);
}
invalidateFilterIfComplete();
emit screenMapperChanged();
}
QObject *FolderModel::appletInterface() const
{
return m_appletInterface;
......@@ -1900,7 +1875,7 @@ void FolderModel::setAppletInterface(QObject *appletInterface)
if (containment) {
Plasma::Corona *corona = containment->corona();
if (corona && m_screenMapper) {
if (corona) {
m_screenMapper->setCorona(corona);
}
setScreen(containment->screen());
......
......@@ -98,7 +98,6 @@ class FOLDERPLUGIN_TESTS_EXPORT FolderModel : public QSortFilterProxyModel, publ
Q_PROPERTY(QString filterPattern READ filterPattern WRITE setFilterPattern NOTIFY filterPatternChanged)
Q_PROPERTY(QStringList filterMimeTypes READ filterMimeTypes WRITE setFilterMimeTypes NOTIFY filterMimeTypesChanged)
Q_PROPERTY(QObject* newMenu READ newMenu CONSTANT)
Q_PROPERTY(ScreenMapper* screenMapper READ screenMapper WRITE setScreenMapper NOTIFY screenMapperChanged)
Q_PROPERTY(QObject* appletInterface READ appletInterface WRITE setAppletInterface NOTIFY appletInterfaceChanged);
public:
......@@ -189,9 +188,6 @@ class FOLDERPLUGIN_TESTS_EXPORT FolderModel : public QSortFilterProxyModel, publ
QStringList filterMimeTypes() const;
void setFilterMimeTypes(const QStringList &mimeList);
ScreenMapper* screenMapper() const;
void setScreenMapper(ScreenMapper* screenMapper);
QObject *appletInterface() const;
void setAppletInterface(QObject *appletInterface);
......@@ -272,7 +268,6 @@ class FOLDERPLUGIN_TESTS_EXPORT FolderModel : public QSortFilterProxyModel, publ
void filterPatternChanged() const;
void filterMimeTypesChanged() const;
void screenChanged() const;
void screenMapperChanged() const;
void appletInterfaceChanged() const;
void requestRename() const;
void move(int x, int y, QList<QUrl> urls);
......
......@@ -32,7 +32,6 @@
#include "viewpropertiesmenu.h"
#include "wheelinterceptor.h"
#include "shortcut.h"
#include "screenmapper.h"
#include <QQmlContext>
#include <QQmlEngine>
......@@ -44,16 +43,6 @@ static QObject *menuHelperSingletonProvider(QQmlEngine *engine, QJSEngine *jsEng
return new MenuHelper();
}
static QObject *screenMapperProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(scriptEngine);
QObject *mapper = ScreenMapper::instance();
engine->setObjectOwnership(mapper, QQmlEngine::CppOwnership);
return mapper;
}
void FolderPlugin::registerTypes(const char *uri)
{
Q_ASSERT(uri == QLatin1String("org.kde.private.desktopcontainment.folder"));
......@@ -71,6 +60,5 @@ void FolderPlugin::registerTypes(const char *uri)
qmlRegisterType<ViewPropertiesMenu>(uri, 0, 1, "ViewPropertiesMenu");
qmlRegisterType<WheelInterceptor>(uri, 0, 1, "WheelInterceptor");
qmlRegisterType<ShortCut>(uri, 0, 1, "ShortCut");
qmlRegisterSingletonType<ScreenMapper>(uri, 0, 1, "ScreenMapper", screenMapperProvider);
}
......@@ -37,7 +37,6 @@ namespace Plasma {
class FOLDERPLUGIN_TESTS_EXPORT ScreenMapper : public QObject
{
Q_OBJECT
Q_PROPERTY(QStringList screenMapping READ screenMapping WRITE setScreenMapping NOTIFY screenMappingChanged)
public:
enum MappingSignalBehavior {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment