kioslave: remove redundant desktop KIO slave

now the home, trash and .directory files will be copied when the desktop
is started (by kcminit) rather than when desktop:/ is accessed for the
first time, no functional change besides improvement including less
.protocol files to parse and one less KIO slave to maintain

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-06-22 01:19:05 +03:00
parent 8bc8384cff
commit 3b2b21d1f7
19 changed files with 64 additions and 718 deletions

View file

@ -19,3 +19,10 @@ install(
DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
)
install(
FILES
data/directory.desktop
data/Trash.desktop
data/Home.desktop
DESTINATION ${KDE4_DATA_INSTALL_DIR}/kcm_desktoppaths
)

View file

@ -6,6 +6,7 @@ Icon=system-file-manager
Exec=kcmshell4 desktoppath
X-KDE-Library=kcm_desktoppaths
X-KDE-Init-Symbol=kcminit_desktoppaths
X-KDE-PluginKeyword=dpath
X-KDE-ParentApp=kcontrol
X-KDE-System-Settings-Parent-Category=account-details

View file

@ -20,10 +20,52 @@
#include "kcmdesktoppaths.h"
#include "globalpaths.h"
#include <QStandardPaths>
#include <QDir>
#include <KStandardDirs>
#include <KPluginFactory>
#include <KPluginLoader>
K_PLUGIN_FACTORY_DEFINITION(KcmDesktopPaths,
registerPlugin<DesktopPathConfig>("dpath");
)
#include <sys/stat.h>
K_PLUGIN_FACTORY_DEFINITION(KcmDesktopPaths, registerPlugin<DesktopPathConfig>("dpath");)
K_EXPORT_PLUGIN(KcmDesktopPaths("kcm_desktoppaths"))
extern "C"
{
Q_DECL_EXPORT void kcminit_desktoppaths()
{
// We can't use KGlobalSettings::desktopPath() here, since it returns the home dir
// if the desktop folder doesn't exist.
QString desktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
if (desktopPath.isEmpty()) {
desktopPath = QDir::homePath() + "/Desktop";
}
// Create the desktop folder if it doesn't exist
bool desktopIsEmpty = false;
const QDir desktopDir(desktopPath);
if (!desktopDir.exists()) {
::mkdir(QFile::encodeName(desktopPath), S_IRWXU);
desktopIsEmpty = true;
} else {
desktopIsEmpty = desktopDir.entryList(QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot).isEmpty();
}
if (desktopIsEmpty) {
// Copy the desktop links and .directory file
const QStringList links = KGlobal::dirs()->findAllResources("data", "kcm_desktoppaths/*", KStandardDirs::NoDuplicates);
foreach (const QString &link, links) {
QString linkname = link.mid(link.lastIndexOf('/'));
// NOTE: special case for the .directory file, it is .desktop file but hidden one
if (linkname.startsWith(QLatin1String("/directory."))) {
linkname = QString::fromLatin1("/.directory");
// NOTE: .desktop file but extension does not matter and is better chopped
} else if (linkname.endsWith(QLatin1String(".desktop"))) {
linkname.chop(8);
}
QFile::copy(link, desktopPath + linkname);
}
}
}
}

View file

@ -1,4 +1,3 @@
add_subdirectory(desktop)
add_subdirectory(floppy)
add_subdirectory(network)
add_subdirectory(remote)

View file

@ -1,32 +0,0 @@
if(ENABLE_TESTING)
add_subdirectory(tests)
endif()
########### next target ###############
set(kio_desktop_PART_SRCS kio_desktop.cpp)
add_executable(kio_desktop ${kio_desktop_PART_SRCS})
target_link_libraries(kio_desktop KDE4::kio)
install(TARGETS kio_desktop DESTINATION ${KDE4_LIBEXEC_INSTALL_DIR} )
########### next target ###############
set(kded_desktopnotifier_PART_SRCS desktopnotifier.cpp )
kde4_add_plugin(kded_desktopnotifier ${kded_desktopnotifier_PART_SRCS})
target_link_libraries(kded_desktopnotifier KDE4::kio)
install(TARGETS kded_desktopnotifier DESTINATION ${KDE4_PLUGIN_INSTALL_DIR} )
########### install files ###############
install( FILES desktopnotifier.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR}/kded )
install( FILES desktop.protocol DESTINATION ${KDE4_SERVICES_INSTALL_DIR} )
install(FILES directory.desktop directory.trash DESTINATION ${KDE4_DATA_INSTALL_DIR}/kio_desktop)
install(FILES Home.desktop DESTINATION ${KDE4_DATA_INSTALL_DIR}/kio_desktop/DesktopLinks)

View file

@ -1,4 +0,0 @@
#! /bin/sh
#This file has output in separate line each file with a .desktop syntax
#that needs to be translated but has a non .desktop extension
find -name \*.trash -print

View file

@ -1,14 +0,0 @@
[Protocol]
exec=kio_desktop
protocol=desktop
Icon=user-desktop
listing=true
reading=true
writing=true
makedir=true
deleting=true
linking=true
moving=true
opening=true
maxInstances=4
Class=:local

View file

@ -1,69 +0,0 @@
/* This file is part of the KDE Project
Copyright (C) 2008, 2009 Fredrik Höglund <fredrik@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "desktopnotifier.h"
#include <QtCore/qfile.h>
#include <KDirWatch>
#include <KGlobal>
#include <KGlobalSettings>
#include <KPluginFactory>
#include <KPluginLoader>
#include <KStandardDirs>
#include <KUrl>
#include <kdirnotify.h>
K_PLUGIN_FACTORY(DesktopNotifierFactory, registerPlugin<DesktopNotifier>();)
K_EXPORT_PLUGIN(DesktopNotifierFactory("kio_desktop"))
DesktopNotifier::DesktopNotifier(QObject *parent, const QList<QVariant> &)
: KDEDModule(parent)
{
dirWatch = new KDirWatch(this);
dirWatch->addDir(KGlobalSettings::desktopPath());
dirWatch->addDir(KGlobal::dirs()->localxdgdatadir() + "Trash/files");
connect(dirWatch, SIGNAL(dirty(QString)), SLOT(dirty(QString)));
}
void DesktopNotifier::watchDir(const QString &path)
{
dirWatch->addDir(path);
}
void DesktopNotifier::dirty(const QString &path)
{
Q_UNUSED(path)
if (path.startsWith(KGlobal::dirs()->localxdgdatadir() + "Trash/files")) {
// Trigger an update of the trash icon
if (QFile::exists(KGlobalSettings::desktopPath() + "/trash.desktop"))
org::kde::KDirNotify::emitFilesChanged(QStringList() << "desktop:/trash.desktop");
} else {
// Emitting FilesAdded forces a re-read of the dir
KUrl url("desktop:/");
url.addPath(KUrl::relativePath(KGlobalSettings::desktopPath(), path));
url.cleanPath();
org::kde::KDirNotify::emitFilesAdded(url.url());
}
}

View file

@ -1,146 +0,0 @@
[Desktop Entry]
Type=Service
Name=Directory Watcher
Name[ar]=مراقب المجلدات
Name[ast]=Observador de carpetes
Name[bg]=Наблюдение на директории
Name[bn]=িি
Name[bs]=Nadzornik fascikli
Name[ca]=Vigilant de directori
Name[ca@valencia]=Vigilant de directori
Name[cs]=Sledování adresářů
Name[da]=Mappeovervåger
Name[de]=Ordnerüberwachung
Name[el]=Επόπτης φακέλων
Name[en_GB]=Directory Watcher
Name[eo]=Kontrolilo de dosierujoj
Name[es]=Observador de carpetas
Name[et]=Kataloogijälgija
Name[eu]=Direktorio-behatzailea
Name[fa]=دیدهبان پوشه
Name[fi]=Kansion tarkkailija
Name[fr]=Surveillance des dossiers
Name[ga]=Fairtheoir Comhadlann
Name[gl]=Vixilante do directorio
Name[gu]=િ
Name[he]=מנטר התיקיות
Name[hi]=
Name[hr]=Nadglednik direktorija
Name[hu]=Könyvtárfigyelő
Name[ia]=Observator de Directorio
Name[id]=Pengawas Direktori
Name[is]=Möppuskoðunartól
Name[it]=Guardia delle cartelle
Name[ja]=
Name[kk]=Каталог бақылаушысы
Name[km]=
Name[kn]= ()
Name[ko]=
Name[lt]=Aplanko stebėtojas
Name[lv]=Mapju novērotājs
Name[mai]=िि ि
Name[ml]= ി
Name[mr]=
Name[nb]=Mappeovervåker
Name[nds]=Ornern beluern
Name[nl]=Mappenbewaker
Name[nn]=Mappeovervaking
Name[pa]=
Name[pl]=Monitorowanie katalogów
Name[pt]=Vigilante de Pastas
Name[pt_BR]=Monitor de pastas
Name[ro]=Supraveghetor dosare
Name[ru]=Наблюдение за каталогом
Name[si]=
Name[sk]=Sledovanie adresárov
Name[sl]=Opazovalnik map
Name[sr]=Надзорник фасцикли
Name[sr@ijekavian]=Надзорник фасцикли
Name[sr@ijekavianlatin]=Nadzornik fascikli
Name[sr@latin]=Nadzornik fascikli
Name[sv]=Katalogövervakare
Name[tg]=Намоишгари феҳрастҳо
Name[th]=
Name[tr]=Dizin İzleyici
Name[ug]=مۇندەرىجە كۆزەتكۈچ
Name[uk]=Нагляд за каталогами
Name[vi]=Trình theo dõi thư mc
Name[wa]=Waiteu des ridants
Name[x-test]=xxDirectory Watcherxx
Name[zh_CN]=
Name[zh_TW]=
ServiceTypes=KDEDModule
X-KDE-ServiceTypes=KDEDModule
X-KDE-Library=desktopnotifier
X-KDE-DBus-ModuleName=desktopnotifier
X-KDE-Kded-load-on-demand=true
X-KDE-Kded-autoload=false
Comment=Monitors directories for changes
Comment[ar]=يراقب تغييرات المجلدات
Comment[ast]=Monitoriza cambeos en carpetes
Comment[bg]=Наблюдение на директории за промени
Comment[bn]=িি িি ি ি
Comment[bs]=Nadgledanje izmjena u fasciklama
Comment[ca]=Controla els canvis en els directoris
Comment[ca@valencia]=Controla els canvis en els directoris
Comment[cs]=Monitoruje změny v adresářích
Comment[da]=Overvåger mapper for ændringer
Comment[de]=Ordner auf Änderungen überwachen
Comment[el]=Επίβλεψη φακέλων για αλλαγές
Comment[en_GB]=Monitors directories for changes
Comment[eo]=Ĝi kontrolas ŝanĝojn de dosierujoj
Comment[es]=Monitoriza cambios en carpetas
Comment[et]=Kataloogide muutuste jälgimine
Comment[eu]=Direktorioetako aldaketak kontrolatzen ditu
Comment[fa]=پوشهها را برای تغییرات دیدهبانی میکند
Comment[fi]=Tarkkailee muutoksia kansioissa
Comment[fr]=Surveille les modifications des dossiers
Comment[ga]=Déan monatóireacht ar chomhadlanna le haghaidh athruithe
Comment[gl]=Vixía os cambios en directorios
Comment[gu]= િ
Comment[he]=מנטר תיקיות לשינויים
Comment[hi]= ि
Comment[hr]=Nadzire promjene u direktorijima
Comment[hu]=Könyvtárak változásainak figyelése
Comment[ia]=Il monitora le directorios pro variationes
Comment[id]=Monitor direktori terhadap perubahan
Comment[is]=Fylgist með breytingum í möppum
Comment[it]=Sorveglia i cambiamenti nelle cartelle
Comment[ja]=
Comment[kk]=Каталог өзгеруін бақылау
Comment[km]=
Comment[kn]= ಿಿ
Comment[ko]=
Comment[lt]=Stebi aplanko pakeitimus
Comment[lv]=Novēro izmaiņas mapēs
Comment[ml]=ി ിി
Comment[mr]=
Comment[nb]=Overvåker mapper etter endringer.
Comment[nds]=Ornern op Ännern beluern
Comment[nl]=Mappen monitoren op wijzigingen
Comment[nn]=Overvakar mapper for endringar
Comment[pa]= ਿ
Comment[pl]=Monitoruje katalogi w poszukiwaniu zmian
Comment[pt]=Vigia as alterações nas pastas
Comment[pt_BR]=Monitora as alterações nas pastas
Comment[ro]=Monitorizează dosarele după modificări
Comment[ru]=Наблюдение за изменениями в каталоге
Comment[si]=
Comment[sk]=Monitoruje zmeny v adresároch
Comment[sl]=Nadzira mape za spremembami
Comment[sr]=Надгледање измена у фасциклама
Comment[sr@ijekavian]=Надгледање измијена у фасциклама
Comment[sr@ijekavianlatin]=Nadgledanje izmijena u fasciklama
Comment[sr@latin]=Nadgledanje izmena u fasciklama
Comment[sv]=Övervakar katalogändringar
Comment[tg]=Тағйиротро дар феҳрастҳо тафтиш мекунад
Comment[th]=
Comment[tr]=Dizinleri değişiklik için izler.
Comment[ug]=مۇندەرىجە ئۆزگىرىشىنى كۆزەتكۈچ
Comment[uk]=Спостереження за змінами у каталогах
Comment[vi]=Theo dõi s thay đi ca các thư mc
Comment[wa]=Corwaite les candjmints ezès ridants
Comment[x-test]=xxMonitors directories for changesxx
Comment[zh_CN]=
Comment[zh_TW]=

View file

@ -1,46 +0,0 @@
/* This file is part of the KDE Project
Copyright (C) 2008, 2009 Fredrik Höglund <fredrik@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef DESKTOPNOTIFIER_H
#define DESKTOPNOTIFIER_H
#include <kdedmodule.h>
#include <QtDBus/QtDBus>
class KDirWatch;
class DesktopNotifier : public KDEDModule
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.DesktopNotifier")
public:
DesktopNotifier(QObject* parent, const QList<QVariant>&);
public slots:
Q_SCRIPTABLE void watchDir(const QString &path);
private slots:
void dirty(const QString &path);
private:
KDirWatch *dirWatch;
};
#endif

View file

@ -1,209 +0,0 @@
/* This file is part of the KDE project
Copyright (C) 2008, 2009 Fredrik Höglund <fredrik@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kio_desktop.h"
#include <KApplication>
#include <KCmdLineArgs>
#include <KConfigGroup>
#include <KDesktopFile>
#include <KGlobalSettings>
#include <KStandardDirs>
#include <kdeversion.h>
#include <kdemacros.h>
#include <kdebug.h>
#include <kio/udsentry.h>
#include <QFile>
#include <QDBusInterface>
#include <QStandardPaths>
#include <QDir>
#include <sys/stat.h>
int main(int argc, char **argv)
{
if (argc != 2) {
fprintf(stderr, "Usage: kio_desktop app-socket\n");
exit(-1);
}
// necessary to use other kio slaves
QCoreApplication app(argc, argv);
KComponentData("kio_desktop", "kdelibs4");
KGlobal::locale();
// start the slave
DesktopProtocol slave(argv[1]);
slave.dispatchLoop();
return 0;
}
DesktopProtocol::DesktopProtocol(const QByteArray &app)
: KIO::ForwardingSlaveBase("desktop", app)
{
checkLocalInstall();
QDBusInterface kded("org.kde.kded", "/kded", "org.kde.kded");
kded.call("loadModule", "desktopnotifier");
}
DesktopProtocol::~DesktopProtocol()
{
}
void DesktopProtocol::checkLocalInstall()
{
// We can't use KGlobalSettings::desktopPath() here, since it returns the home dir
// if the desktop folder doesn't exist.
QString desktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
if (desktopPath.isEmpty()) {
desktopPath = QDir::homePath() + "/Desktop";
}
// Create the desktop folder if it doesn't exist
bool desktopIsEmpty = false;
const QDir desktopDir(desktopPath);
if (!desktopDir.exists()) {
::mkdir(QFile::encodeName(desktopPath), S_IRWXU);
desktopIsEmpty = true;
} else {
desktopIsEmpty = desktopDir.entryList(QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot).isEmpty();
}
if (desktopIsEmpty) {
// Copy the .directory file
QFile::copy(KStandardDirs::locate("data", "kio_desktop/directory.desktop"),
desktopPath + "/.directory");
// Copy the trash link
QFile::copy(KStandardDirs::locate("data", "kio_desktop/directory.trash"),
desktopPath + "/trash.desktop");
// Copy the desktop links
const QStringList links = KGlobal::dirs()->findAllResources("data", "kio_desktop/DesktopLinks/*",
KStandardDirs::NoDuplicates);
foreach (const QString &link, links) {
KDesktopFile file(link);
if (!file.desktopGroup().readEntry("Hidden", false))
QFile::copy(link, desktopPath + link.mid(link.lastIndexOf('/')));
}
}
}
bool DesktopProtocol::rewriteUrl(const KUrl &url, KUrl &newUrl)
{
newUrl.setProtocol("file");
newUrl.setPath(KGlobalSettings::desktopPath());
newUrl.addPath(url.path());
return true;
}
void DesktopProtocol::listDir(const KUrl &url)
{
KIO::ForwardingSlaveBase::listDir(url);
KUrl actual;
rewriteUrl(url, actual);
QDBusInterface kded("org.kde.kded", "/modules/desktopnotifier", "org.kde.DesktopNotifier");
kded.call("watchDir", actual.path());
}
QString DesktopProtocol::desktopFile(KIO::UDSEntry &entry) const
{
const QString name = entry.stringValue(KIO::UDSEntry::UDS_NAME);
if (name == "." || name == "..")
return QString();
KUrl url = processedUrl();
url.addPath(name);
if (entry.isDir()) {
url.addPath(".directory");
if (!KGlobal::dirs()->exists(url.path()))
return QString();
return url.path();
}
if (KDesktopFile::isDesktopFile(url.path()))
return url.path();
return QString();
}
void DesktopProtocol::prepareUDSEntry(KIO::UDSEntry &entry, bool listing) const
{
ForwardingSlaveBase::prepareUDSEntry(entry, listing);
const QString path = desktopFile(entry);
if (!path.isEmpty()) {
KDesktopFile file(path);
const QString name = file.readName();
if (!name.isEmpty())
entry.insert(KIO::UDSEntry::UDS_DISPLAY_NAME, name);
if (file.noDisplay() || !file.tryExec())
entry.insert(KIO::UDSEntry::UDS_HIDDEN, 1);
}
// Set the target URL to the local path
entry.insert(KIO::UDSEntry::UDS_TARGET_URL, entry.stringValue(KIO::UDSEntry::UDS_LOCAL_PATH));
}
void DesktopProtocol::rename(const KUrl &src, const KUrl &dest, KIO::JobFlags flags)
{
KUrl url;
rewriteUrl(src, url);
if (src.protocol() != "desktop" || dest.protocol() != "desktop" ||
!KDesktopFile::isDesktopFile(url.path()))
{
ForwardingSlaveBase::rename(src, dest, flags);
return;
}
QString friendlyName;
KUrl destUrl = dest;
if (dest.url().endsWith(".desktop")) {
const QString fileName = dest.fileName();
friendlyName = KIO::decodeFileName(fileName.left(fileName.length() - 8));
} else {
friendlyName = KIO::decodeFileName(dest.fileName());
destUrl.setFileName(destUrl.fileName() + ".desktop");
}
// Update the value of the Name field in the file.
KDesktopFile file(url.path());
KConfigGroup cg(file.desktopGroup());
cg.writeEntry("Name", friendlyName);
cg.writeEntry("Name", friendlyName, KConfigGroup::Persistent | KConfigGroup::Localized);
cg.sync();
if (src.url() != destUrl.url())
ForwardingSlaveBase::rename(src, destUrl, flags);
else
finished();
}

View file

@ -1,41 +0,0 @@
/* This file is part of the KDE project
Copyright (C) 2008, 2009 Fredrik Höglund <fredrik@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KIO_DESKTOP_H
#define KIO_DESKTOP_H
#include <kio/forwardingslavebase.h>
class DesktopProtocol : public KIO::ForwardingSlaveBase
{
Q_OBJECT
public:
DesktopProtocol(const QByteArray &app);
virtual ~DesktopProtocol();
protected:
void checkLocalInstall();
QString desktopFile(KIO::UDSEntry&) const;
virtual bool rewriteUrl(const KUrl &url, KUrl &newUrl);
virtual void listDir(const KUrl &url);
virtual void prepareUDSEntry(KIO::UDSEntry &entry, bool listing=false) const;
virtual void rename(const KUrl &, const KUrl &, KIO::JobFlags flags);
};
#endif

View file

@ -1,8 +0,0 @@
#include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. )
set(testdesktop_SRCS kio_desktop_test.cpp)
kde4_add_test(testdesktop ${testdesktop_SRCS})
target_link_libraries(testdesktop KDE4::kio KDE4::solid ${QT_QTTEST_LIBRARY})

View file

@ -1,132 +0,0 @@
/* This file is part of the KDE project
Copyright (C) 2009 David Faure <faure@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <kdirlister.h>
#include <ktemporaryfile.h>
#include <kdebug.h>
#include <QStandardPaths>
#include <QObject>
#include <qtest_kde.h>
#include <kio/job.h>
#include <kio/copyjob.h>
class TestDesktop : public QObject
{
Q_OBJECT
public:
TestDesktop() {}
private Q_SLOTS:
void initTestCase()
{
setenv( "KDE_FORK_SLAVES", "yes", true );
// copied from kio_desktop.cpp:
m_desktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
if (m_desktopPath.isEmpty())
m_desktopPath = QDir::homePath() + "/Desktop";
// Warning, this defaults to $HOME/Desktop, the _real_ desktop dir.
m_testFileName = "kio_desktop_test_file";
}
void cleanupTestCase()
{
QFile::remove(m_desktopPath + '/' + m_testFileName);
QFile::remove(m_desktopPath + '/' + m_testFileName + ".part");
}
void testCopyToDesktop()
{
KTemporaryFile tempFile;
QVERIFY(tempFile.open());
tempFile.write( "Hello world\n", 12 );
QString fileName = tempFile.fileName();
tempFile.close();
KIO::Job* job = KIO::file_copy(fileName, KUrl("desktop:/" + m_testFileName), -1, KIO::HideProgressInfo);
job->setUiDelegate(0);
QVERIFY(job->exec());
QVERIFY(QFile::exists(m_desktopPath + '/' + m_testFileName));
}
void testMostLocalUrl() // relies on testCopyToDesktop being run before
{
const KUrl desktopUrl("desktop:/" + m_testFileName);
const QString filePath(m_desktopPath + '/' + m_testFileName);
KIO::StatJob* job = KIO::mostLocalUrl(KUrl(desktopUrl), KIO::HideProgressInfo);
QVERIFY(job);
bool ok = job->exec();
QVERIFY(ok);
QCOMPARE(job->mostLocalUrl().toLocalFile(), filePath);
}
void testRename_data()
{
QTest::addColumn<bool>("withDirListerCache");
QTest::addColumn<QString>("srcFile");
QTest::addColumn<QString>("destFile");
const QString orig = "desktop:/" + m_testFileName;
const QString part = orig + ".part";
QTest::newRow("from orig to .part") << false << orig << part;
QTest::newRow("from .part to orig") << false << part << orig;
// Warnings: all tests without dirlister cache should above this line
// and all tests with it should be below - the cache stays forever once it exists.
QTest::newRow("from orig to .part, with cache") << true << orig << part;
QTest::newRow("from .part to orig, with cache (#218719)") << true << part << orig;
}
void testRename() // relies on testCopyToDesktop being run before
{
QFETCH(bool, withDirListerCache);
QFETCH(QString, srcFile);
QFETCH(QString, destFile);
if (withDirListerCache) {
KDirLister lister;
lister.openUrl(KUrl("desktop:/"));
QEventLoop eventLoop;
connect(&lister, SIGNAL(completed()), &eventLoop, SLOT(quit()));
eventLoop.exec(QEventLoop::ExcludeUserInputEvents);
}
const KUrl srcUrl(srcFile);
const KUrl destUrl(destFile);
const QString srcFilePath(m_desktopPath + srcUrl.path());
QVERIFY(QFile::exists(srcFilePath));
const QString destFilePath(m_desktopPath + destUrl.path());
QVERIFY(!QFile::exists(destFilePath));
KIO::CopyJob* job = KIO::move(srcUrl, destUrl, KIO::HideProgressInfo);
job->setUiDelegate(0);
QVERIFY(job);
bool ok = job->exec();
QVERIFY(ok);
QVERIFY(!QFile::exists(srcFilePath));
QVERIFY(QFile::exists(destFilePath));
}
private:
QString m_desktopPath;
QString m_testFileName;
};
QTEST_KDEMAIN(TestDesktop, NoGUI)
#include "kio_desktop_test.moc"

View file

@ -431,7 +431,7 @@ void FolderView::init()
const QDir desktopFolder(desktopPath);
if (desktopPath != QDir::homePath() && desktopFolder.exists()) {
path = QString("desktop:/");
path = desktopPath;
}
}
setUrl(cg.readEntry("url", KUrl(path)));
@ -653,9 +653,9 @@ void FolderView::addUrls(const KUrl::List& urls)
void FolderView::createConfigurationInterface(KConfigDialog *parent)
{
QWidget *widgetFilter = new QWidget;
QWidget *widgetDisplay = new QWidget;
QWidget *widgetLocation = new QWidget;
QWidget *widgetFilter = new QWidget();
QWidget *widgetDisplay = new QWidget();
QWidget *widgetLocation = new QWidget();
uiFilter.setupUi(widgetFilter);
uiDisplay.setupUi(widgetDisplay);
uiLocation.setupUi(widgetLocation);
@ -674,7 +674,7 @@ void FolderView::createConfigurationInterface(KConfigDialog *parent)
const bool desktopVisible = desktopPath != QDir::homePath() && desktopFolder.exists();
uiLocation.showDesktopFolder->setVisible(desktopVisible);
if (desktopVisible && m_url == KUrl("desktop:/")) {
if (desktopVisible && m_url == KUrl(desktopPath)) {
uiLocation.showDesktopFolder->setChecked(true);
uiLocation.placesCombo->setEnabled(false);
uiLocation.lineEdit->setEnabled(false);
@ -835,7 +835,7 @@ void FolderView::configAccepted()
KUrl url;
if (uiLocation.showDesktopFolder->isChecked()) {
url = KUrl("desktop:/");
url = KUrl(KGlobalSettings::desktopPath());
} else if (uiLocation.showPlace->isChecked()) {
PlacesFilterModel *filter = static_cast<PlacesFilterModel*>(uiLocation.placesCombo->model());
KFilePlacesModel *model = static_cast<KFilePlacesModel*>(filter->sourceModel());
@ -1418,7 +1418,7 @@ void FolderView::setUrl(const KUrl &url)
}
// Only parse desktop files when sorting if we're showing the desktop folder
m_model->setParseDesktopFiles(m_url.protocol() == "desktop");
m_model->setParseDesktopFiles(m_url == KUrl(KGlobalSettings::desktopPath()));
setAppletTitle();
}
@ -1429,7 +1429,7 @@ void FolderView::setAppletTitle()
} else if (m_labelType == FolderView::FullPath) {
m_titleText = m_url.path();
} else if (m_labelType == FolderView::PlaceName) {
if (m_url == KUrl("desktop:/")) {
if (m_url == KUrl(KGlobalSettings::desktopPath())) {
m_titleText = i18n("Desktop Folder");
} else {
m_titleText = m_url.pathOrUrl();
@ -2185,7 +2185,7 @@ void FolderView::updateIconWidget()
KFileItem item = m_dirModel->itemForIndex(QModelIndex());
if (!item.isNull() && item.iconName() != "inode-directory") {
m_icon = KIcon(item.iconName(), 0, item.overlays());
} else if (m_url.protocol() == "desktop") {
} else if (m_url == KUrl(KGlobalSettings::desktopPath())) {
m_icon = KIcon("user-desktop");
} else if (m_url.protocol() == "trash") {
m_icon = m_model->rowCount() > 0 ? KIcon("user-trash-full") : KIcon("user-trash");

View file

@ -23,14 +23,13 @@
#include <KDesktopFile>
#include <KDirModel>
#include <KStringHandler>
#include <KDebug>
#include <kde_file.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <kde_file.h>
ProxyModel::ProxyModel(QObject *parent)
: QSortFilterProxyModel(parent),
m_filterMode(NoFilter),
@ -145,7 +144,6 @@ bool ProxyModel::isDir(const QModelIndex &index, const KDirModel *dirModel) cons
return false;
}
#include <KDebug>
bool ProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
const KDirModel *dirModel = static_cast<KDirModel*>(sourceModel());