From 865f314dd5ed55508f45a32973b709b79a541e36 Mon Sep 17 00:00:00 2001 From: tpearson Date: Fri, 11 Dec 2009 03:46:01 +0000 Subject: kdelibs update to Trinity v3.5.11 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1061230 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kdecore/kglobalsettings.cpp | 51 ++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 15 deletions(-) (limited to 'kdecore/kglobalsettings.cpp') 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 #include +#include +#include +#include + #ifdef Q_WS_X11 #include #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); -- cgit v1.2.1