diff -ur kdelibs-3.5.10/kdecore/kglobalsettings.cpp kdelibs-3.5.10-kglobalsettings-xdg-user-dirs/kdecore/kglobalsettings.cpp --- kdelibs-3.5.10/kdecore/kglobalsettings.cpp 2005-10-10 17:06:03.000000000 +0200 +++ kdelibs-3.5.10-kglobalsettings-xdg-user-dirs/kdecore/kglobalsettings.cpp 2019-08-10 17:57:32.256483651 +0200 @@ -50,6 +50,10 @@ #include #include +#include +#include +#include + #ifdef Q_WS_X11 #include #endif @@ -77,6 +81,31 @@ KGlobalSettings::KMouseSettings *KGlobalSettings::s_mouseSettings = 0; +// helper function for reading xdg user dirs: it is required in order to take +// care of locale stuff +void readXdgUserDirs(QString *desktop, QString *documents) +{ + QFile f( QDir::homeDirPath() + "/.config/user-dirs.dirs" ); + + if (!f.open(IO_ReadOnly)) + return; + + // set the codec for the current locale + QTextStream s(&f); + s.setCodec( QTextCodec::codecForLocale() ); + + QString line = s.readLine(); + while (!line.isNull()) + { + if (line.startsWith("XDG_DESKTOP_DIR=")) + *desktop = line.remove("XDG_DESKTOP_DIR=").remove("\"").replace("$HOME", QDir::homeDirPath()); + else if (line.startsWith("XDG_DOCUMENTS_DIR=")) + *documents = line.remove("XDG_DOCUMENTS_DIR=").remove("\"").replace("$HOME", QDir::homeDirPath()); + + line = s.readLine(); + } +} + int KGlobalSettings::dndEventDelay() { KConfigGroup g( KGlobal::config(), "General" ); @@ -483,13 +512,27 @@ KConfigGroup g( KGlobal::config(), "Paths" ); - // Desktop Path - *s_desktopPath = QDir::homeDirPath() + "/Desktop/"; - *s_desktopPath = g.readPathEntry( "Desktop", *s_desktopPath); + // Read desktop and documents path using XDG_USER_DIRS + readXdgUserDirs(s_desktopPath, s_documentPath); + + if (s_desktopPath->isEmpty() == true) { + *s_desktopPath = QDir::homeDirPath() + "/Desktop/"; + } *s_desktopPath = QDir::cleanDirPath( *s_desktopPath ); if ( !s_desktopPath->endsWith("/") ) s_desktopPath->append('/'); + if (s_documentPath->isEmpty() == true) { +#ifdef Q_WS_WIN + *s_documentPath = getWin32ShellFoldersPath("Personal"); +#else + *s_documentPath = QDir::homeDirPath() + "/Documents/"; +#endif + } + *s_documentPath = QDir::cleanDirPath( *s_documentPath ); + if ( !s_documentPath->endsWith("/")) + s_documentPath->append('/'); + // Trash Path - TODO remove in KDE4 (kio_trash can't use it for interoperability reasons) *s_trashPath = *s_desktopPath + i18n("Trash") + "/"; *s_trashPath = g.readPathEntry( "Trash" , *s_trashPath); @@ -510,18 +553,6 @@ if ( !s_autostartPath->endsWith("/") ) s_autostartPath->append('/'); - // Document Path - *s_documentPath = g.readPathEntry( "Documents", -#ifdef Q_WS_WIN - getWin32ShellFoldersPath("Personal") -#else - QDir::homeDirPath() -#endif - ); - *s_documentPath = QDir::cleanDirPath( *s_documentPath ); - if ( !s_documentPath->endsWith("/")) - s_documentPath->append('/'); - // Make sure this app gets the notifications about those paths if (kapp) kapp->addKipcEventMask(KIPC::SettingsChanged);