diff options
Diffstat (limited to 'kdecore/kglobalsettings.cpp')
-rw-r--r-- | kdecore/kglobalsettings.cpp | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/kdecore/kglobalsettings.cpp b/kdecore/kglobalsettings.cpp index b5539fb22..25e95f5c6 100644 --- a/kdecore/kglobalsettings.cpp +++ b/kdecore/kglobalsettings.cpp @@ -50,6 +50,10 @@ static QRgb qt_colorref2qrgb(COLORREF col) #include <stdlib.h> #include <kprotocolinfo.h> +#include <qtextcodec.h> +#include <qtextstream.h> +#include <qfile.h> + #ifdef Q_WS_X11 #include <X11/Xlib.h> #endif @@ -77,6 +81,31 @@ QColor *KGlobalSettings::alternateColor = 0; 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,17 @@ void KGlobalSettings::initStatic() // should be called initPaths(). Don't put an 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); + *s_desktopPath = QDir::cleanDirPath( *s_desktopPath ); if ( !s_desktopPath->endsWith("/") ) s_desktopPath->append('/'); + *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 +543,6 @@ void KGlobalSettings::initStatic() // should be called initPaths(). Don't put an 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); |