Sophie

Sophie

distrib > Mandriva > 2009.0 > x86_64 > by-pkgid > a4e51422fe1b8d073f47c12205a319a3 > files > 19

kdelibs-3.5.10-4.4mdv2009.0.src.rpm

--- kdelibs-3.5.7/kdecore/kglobalsettings.cpp.fix_default_document_path	2005-10-10 12:06:03.000000000 -0300
+++ kdelibs-3.5.7/kdecore/kglobalsettings.cpp	2007-09-27 18:59:32.000000000 -0300
@@ -50,6 +50,10 @@ static QRgb qt_colorref2qrgb(COLORREF co
 #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 
 
 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() // sh
 
     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() // sh
     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);