Improved support for XDG folders without requiring xdg-user-dirs to be installed.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/69/head
Michele Calgaro hace 4 años
padre ecd1e4bd40
commit 394c9f5c0e
Firmado por: MicheleC
ID de clave GPG: 2A75B7CA8ADED5CF

@ -321,6 +321,12 @@ TQString TDEConfigBase::readEntry( const char *pKey,
else if (aVarName == "XDG_PICTURES_DIR") {
result = TDEGlobalSettings::picturesPath();
}
else if (aVarName == "XDG_PUBLICSHARE_DIR") {
result = TDEGlobalSettings::publicSharePath();
}
else if (aVarName == "XDG_TEMPLATES_DIR") {
result = TDEGlobalSettings::templatesPath();
}
else if (aVarName == "XDG_VIDEOS_DIR") {
result = TDEGlobalSettings::videosPath();
}

@ -87,42 +87,90 @@ TQColor *TDEGlobalSettings::alternateColor = 0;
TDEGlobalSettings::KMouseSettings *TDEGlobalSettings::s_mouseSettings = 0;
// helper function for reading xdg user dirs: it is required in order to take
// care of locale stuff
void readXdgUserDirs(TQString *desktop, TQString *documents, TQString *videos, TQString *music,
TQString *download, TQString *pictures, TQString *templates, TQString *publicShare)
// Helper function for reading xdg user dirs.
// Returns sane values in case the user dir file can't be read
static void readXdgUserDirs(TQString *desktop, TQString *documents, TQString *download, TQString *music,
TQString *pictures, TQString *publicShare, TQString *templates, TQString *videos)
{
TQFile f( TQDir::homeDirPath() + "/.config/user-dirs.dirs" );
if (!f.open(IO_ReadOnly))
return;
// set the codec for the current locale
TQTextStream s(&f);
s.setCodec( TQTextCodec::codecForLocale() );
TQString line = s.readLine();
while (!line.isNull())
TQFile dirsFile(TQDir::homeDirPath() + "/.config/user-dirs.dirs");
if (dirsFile.open(IO_ReadOnly))
{
if (line.startsWith("XDG_DESKTOP_DIR="))
*desktop = line.remove("XDG_DESKTOP_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
else if (line.startsWith("XDG_DOCUMENTS_DIR="))
*documents = line.remove("XDG_DOCUMENTS_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
else if (line.startsWith("XDG_MUSIC_DIR="))
*videos = line.remove("XDG_MUSIC_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
else if (line.startsWith("XDG_DOWNLOAD_DIR="))
*download = line.remove("XDG_DOWNLOAD_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
else if (line.startsWith("XDG_VIDEOS_DIR="))
*music = line.remove("XDG_VIDEOS_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
else if (line.startsWith("XDG_PICTURES_DIR="))
*pictures = line.remove("XDG_PICTURES_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
else if (line.startsWith("XDG_TEMPLATES_DIR="))
*templates = line.remove("XDG_TEMPLATES_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
else if (line.startsWith("XDG_PUBLICSHARE_DIR="))
*publicShare = line.remove("XDG_PUBLICSHARE_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
line = s.readLine();
// set the codec for the current locale
TQTextStream stream(&dirsFile);
stream.setCodec(TQTextCodec::codecForLocale());
while (!stream.atEnd())
{
TQString line = stream.readLine();
if (line.startsWith("XDG_DESKTOP_DIR="))
{
*desktop = line.remove("XDG_DESKTOP_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
}
else if (line.startsWith("XDG_DOCUMENTS_DIR="))
{
*documents = line.remove("XDG_DOCUMENTS_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
}
else if (line.startsWith("XDG_DOWNLOAD_DIR="))
{
*download = line.remove("XDG_DOWNLOAD_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
}
else if (line.startsWith("XDG_MUSIC_DIR="))
{
*music = line.remove("XDG_MUSIC_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
}
else if (line.startsWith("XDG_PICTURES_DIR="))
{
*pictures = line.remove("XDG_PICTURES_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
}
else if (line.startsWith("XDG_PUBLICSHARE_DIR="))
{
*publicShare = line.remove("XDG_PUBLICSHARE_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
}
else if (line.startsWith("XDG_TEMPLATES_DIR="))
{
*templates = line.remove("XDG_TEMPLATES_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
}
else if (line.startsWith("XDG_VIDEOS_DIR="))
{
*videos = line.remove("XDG_VIDEOS_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
}
}
dirsFile.close();
}
// Use sane values in case some paths are missing
if (desktop->isEmpty())
{
*desktop = TQDir::homeDirPath() + "/" + i18n("Desktop") + "/";
}
if (documents->isEmpty())
{
*documents = TQDir::homeDirPath() + "/" + i18n("Documents") + "/";
}
if (download->isEmpty())
{
*download = TQDir::homeDirPath() + "/" + i18n("Downloads") + "/";
}
if (music->isEmpty())
{
*music = TQDir::homeDirPath() + "/" + i18n("Music") + "/";
}
if (pictures->isEmpty())
{
*pictures = TQDir::homeDirPath() + "/" + i18n("Pictures") + "/";
}
if (publicShare->isEmpty())
{
*publicShare = TQDir::homeDirPath() + "/" + i18n("Public") + "/";
}
if (templates->isEmpty())
{
*templates = TQDir::homeDirPath() + "/" + i18n("Templates") + "/";
}
if (videos->isEmpty())
{
*videos = TQDir::homeDirPath() + "/" + i18n("Videos") + "/";
}
}
int TDEGlobalSettings::dndEventDelay()
@ -525,63 +573,61 @@ TQFont TDEGlobalSettings::largeFont(const TQString &text)
return *_largeFont;
}
void TDEGlobalSettings::initStatic() // should be called initPaths(). Don't put anything else here.
void TDEGlobalSettings::initPaths()
{
if ( s_desktopPath != 0 )
return;
if (s_desktopPath)
{
return;
}
s_desktopPath = new TQString();
s_autostartPath = new TQString();
s_trashPath = new TQString();
s_desktopPath = new TQString();
s_documentPath = new TQString();
s_videosPath = new TQString();
s_musicPath = new TQString();
s_downloadPath = new TQString();
s_musicPath = new TQString();
s_picturesPath = new TQString();
s_templatesPath = new TQString();
s_publicSharePath = new TQString();
s_templatesPath = new TQString();
s_videosPath = new TQString();
TDEConfigGroup g( TDEGlobal::config(), "Paths" );
// Read desktop and documents path using XDG_USER_DIRS
readXdgUserDirs(s_desktopPath, s_documentPath, s_musicPath, s_videosPath,
s_downloadPath, s_picturesPath, s_templatesPath, s_publicSharePath);
if (s_desktopPath->isEmpty() == true) {
*s_desktopPath = TQDir::homeDirPath() + "/Desktop/";
}
// Read xdg folder paths
readXdgUserDirs(s_desktopPath, s_documentPath, s_downloadPath, s_musicPath,
s_picturesPath, s_publicSharePath, s_templatesPath, s_videosPath);
*s_desktopPath = TQDir::cleanDirPath( *s_desktopPath );
if ( !s_desktopPath->endsWith("/") )
*s_desktopPath = TQDir::cleanDirPath(*s_desktopPath);
if (!s_desktopPath->endsWith("/"))
s_desktopPath->append('/');
*s_documentPath = TQDir::cleanDirPath( *s_documentPath );
if ( !s_documentPath->endsWith("/"))
*s_documentPath = TQDir::cleanDirPath(*s_documentPath);
if (!s_documentPath->endsWith("/"))
s_documentPath->append('/');
*s_musicPath = TQDir::cleanDirPath( *s_musicPath );
if ( !s_musicPath->endsWith("/"))
s_musicPath->append('/');
*s_videosPath = TQDir::cleanDirPath( *s_videosPath );
if ( !s_videosPath->endsWith("/"))
s_videosPath->append('/');
*s_downloadPath = TQDir::cleanDirPath( *s_downloadPath );
if ( !s_downloadPath->endsWith("/"))
*s_downloadPath = TQDir::cleanDirPath(*s_downloadPath);
if (!s_downloadPath->endsWith("/"))
s_downloadPath->append('/');
*s_picturesPath = TQDir::cleanDirPath( *s_picturesPath );
if ( !s_picturesPath->endsWith("/"))
*s_musicPath = TQDir::cleanDirPath(*s_musicPath);
if (!s_musicPath->endsWith("/"))
s_musicPath->append('/');
*s_picturesPath = TQDir::cleanDirPath(*s_picturesPath);
if (!s_picturesPath->endsWith("/"))
s_picturesPath->append('/');
*s_templatesPath = TQDir::cleanDirPath( *s_templatesPath );
if ( !s_templatesPath->endsWith("/"))
*s_publicSharePath = TQDir::cleanDirPath(*s_publicSharePath);
if (!s_publicSharePath->endsWith("/"))
s_publicSharePath->append('/');
*s_templatesPath = TQDir::cleanDirPath(*s_templatesPath);
if (!s_templatesPath->endsWith("/"))
s_templatesPath->append('/');
*s_publicSharePath = TQDir::cleanDirPath( *s_publicSharePath );
if ( !s_publicSharePath->endsWith("/"))
s_publicSharePath->append('/');
*s_videosPath = TQDir::cleanDirPath(*s_videosPath);
if (!s_videosPath->endsWith("/"))
s_videosPath->append('/');
// Trash Path - TODO remove in KDE4 (tdeio_trash can't use it for interoperability reasons)
*s_trashPath = *s_desktopPath + i18n("Trash") + "/";
@ -647,18 +693,18 @@ void TDEGlobalSettings::rereadPathSettings()
s_desktopPath = 0L;
delete s_documentPath;
s_documentPath = 0L;
delete s_videosPath;
s_videosPath = 0L;
delete s_picturesPath;
s_picturesPath = 0L;
delete s_downloadPath;
s_downloadPath = 0L;
delete s_musicPath;
s_musicPath = 0L;
delete s_templatesPath;
s_templatesPath = 0L;
delete s_picturesPath;
s_picturesPath = 0L;
delete s_publicSharePath;
s_publicSharePath = 0L;
delete s_templatesPath;
s_templatesPath = 0L;
delete s_videosPath;
s_videosPath = 0L;
}
TDEGlobalSettings::KMouseSettings & TDEGlobalSettings::mouseSettings()

@ -226,68 +226,68 @@ class TDECORE_EXPORT TDEGlobalSettings
*/
static KMouseSettings & mouseSettings();
/**
* The path to the desktop directory of the current user.
* @return the user's desktop directory
*/
static TQString desktopPath() { initStatic(); return *s_desktopPath; }
/**
* The path to the autostart directory of the current user.
* @return the path of the autostart directory
*/
static TQString autostartPath() { initStatic(); return *s_autostartPath; }
static TQString autostartPath() { initPaths(); return *s_autostartPath; }
/**
* DEPRECATED (starting from kde-3.4).
* This isn't where the trash contents is, anymore.
* Use TDEIO::trash() to trash files, "trash:/" to list the trash contents.
*/
static TQString trashPath() { initStatic(); return *s_trashPath; }
static TQString trashPath() { initPaths(); return *s_trashPath; }
// KDE4: if you want to remove the above, move it to kdesktop/init.cc, which needs
// to know the old location of the trash
/**
* The path to the desktop directory of the current user.
* @return the user's desktop directory
*/
static TQString desktopPath() { initPaths(); return *s_desktopPath; }
/**
* The path where documents are stored of the current user.
* @return the path of the document directory
*/
static TQString documentPath() { initStatic(); return *s_documentPath; }
static TQString documentPath() { initPaths(); return *s_documentPath; }
/**
* The path where documents are stored of the current user.
* @return the path of the videos directory
* @return the path of the downloads directory
*/
static TQString videosPath() { initStatic(); return *s_videosPath; }
static TQString downloadPath() { initPaths(); return *s_downloadPath; }
/**
* The path where documents are stored of the current user.
* @return the path of the music directory
*/
static TQString musicPath() { initStatic(); return *s_musicPath; }
static TQString musicPath() { initPaths(); return *s_musicPath; }
/**
* The path where documents are stored of the current user.
* @return the path of the downloads directory
* @return the path of the pictures directory
*/
static TQString downloadPath() { initStatic(); return *s_downloadPath; }
static TQString picturesPath() { initPaths(); return *s_picturesPath; }
/**
* The path where documents are stored of the current user.
* @return the path of the pictures directory
* The path of the public share of the current user.
* @return the path of the public share directory
*/
static TQString picturesPath() { initStatic(); return *s_picturesPath; }
static TQString publicSharePath() { initPaths(); return *s_publicSharePath; }
/**
* The path where templates are stored of the current user.
* @return the path of the templates directory
*/
static TQString templatesPath() { initStatic(); return *s_templatesPath; }
static TQString templatesPath() { initPaths(); return *s_templatesPath; }
/**
* The path of the public share of the current user.
* @return the path of the public share directory
* The path where documents are stored of the current user.
* @return the path of the videos directory
*/
static TQString publicSharePath() { initStatic(); return *s_publicSharePath; }
static TQString videosPath() { initPaths(); return *s_videosPath; }
/**
* The default color to use when highlighting toolbar buttons.
@ -572,7 +572,7 @@ private:
/**
* reads in all paths from kdeglobals
*/
static void initStatic();
static void initPaths();
/**
* initialize colors
*/
@ -591,16 +591,16 @@ private:
static void rereadMouseSettings();
static TQString* s_desktopPath;
static TQString* s_autostartPath;
static TQString* s_trashPath;
static TQString* s_documentPath;
static TQString* s_picturesPath;
static TQString* s_templatesPath;
static TQString* s_publicSharePath;
static TQString* s_downloadPath;
static TQString* s_musicPath;
static TQString* s_videosPath;
static TQString *s_desktopPath;
static TQString *s_autostartPath;
static TQString *s_trashPath;
static TQString *s_documentPath;
static TQString *s_picturesPath;
static TQString *s_templatesPath;
static TQString *s_publicSharePath;
static TQString *s_downloadPath;
static TQString *s_musicPath;
static TQString *s_videosPath;
static TQFont *_generalFont;
static TQFont *_fixedFont;
static TQFont *_toolBarFont;
@ -608,15 +608,15 @@ private:
static TQFont *_windowTitleFont;
static TQFont *_taskbarFont;
static TQFont *_largeFont;
static TQColor * _trinity4Blue;
static TQColor * _inactiveBackground;
static TQColor * _inactiveForeground;
static TQColor * _activeBackground;
static TQColor * _buttonBackground;
static TQColor * _selectBackground;
static TQColor * _linkColor;
static TQColor * _visitedLinkColor;
static TQColor * alternateColor;
static TQColor *_trinity4Blue;
static TQColor *_inactiveBackground;
static TQColor *_inactiveForeground;
static TQColor *_activeBackground;
static TQColor *_buttonBackground;
static TQColor *_selectBackground;
static TQColor *_linkColor;
static TQColor *_visitedLinkColor;
static TQColor *alternateColor;
static KMouseSettings *s_mouseSettings;
friend class TDEApplication;

@ -2630,13 +2630,7 @@ KURLPropsPlugin::KURLPropsPlugin( KPropertiesDialog *_props )
KFileItem * item = properties->item();
if (item && item->mimetype() == "media/builtin-mydocuments") {
URLStr = TQString::null;
TDEConfig xdguserconfig( TQDir::homeDirPath()+"/.config/user-dirs.dirs" );
URLEdit->setMode(KFile::Directory);
URLEdit->setURL( xdguserconfig.readPathEntry( "XDG_DOCUMENTS_DIR", TQDir::homeDirPath() + "/Documents").remove( "\"" ));
}
else if (item && item->mimetype().startsWith("media/builtin-")) {
if (item && item->mimetype().startsWith("media/builtin-")) {
URLEdit->setEnabled(false);
}
@ -2679,20 +2673,7 @@ void KURLPropsPlugin::applyChanges()
TQString path = properties->kurl().path();
KFileItem * item = properties->item();
if (item && item->mimetype() == "media/builtin-mydocuments") {
TDEConfig xdgconfig(TQDir::homeDirPath()+"/.config/user-dirs.dirs" );
if (xdgconfig.isReadOnly()) {
KMessageBox::sorry( 0, i18n("<qt>Could not save properties. You do not have "
"sufficient access to write to <b>%1</b>.</qt>").arg(path));
return;
}
else {
xdgconfig.writePathEntry( "XDG_DOCUMENTS_DIR", '"'+ URLEdit->url() + '"', true, false, false, false );
xdgconfig.sync();
return;
}
}
else if (item && item->mimetype().startsWith("media/builtin-")) {
if (item && item->mimetype().startsWith("media/builtin-")) {
return;
}

@ -57,58 +57,19 @@ KFileSpeedBar::KFileSpeedBar( TQWidget *parent, const char *name )
}
u.setPath( TQDir::homeDirPath() );
insertItem( u, i18n("Home Folder"), false,
"folder_home" );
insertItem( u, i18n("Home Folder"), false, "folder_home" );
u = "media:/";
if ( KProtocolInfo::isKnownProtocol( u ) )
insertItem( u, i18n("Storage Media"), false,
KProtocolInfo::icon( "media" ) );
if ( TQFile::exists( TQDir::homeDirPath()+"/.config/user-dirs.dirs" ) )
{
TQString download, music, pictures, videos, templates, publicShares;
TQFile f( TQDir::homeDirPath()+"/.config/user-dirs.dirs" );
if (!f.open(IO_ReadOnly))
return;
TQTextStream s( &f );
s.setCodec( TQTextCodec::codecForLocale() );
// read the xdg user dirs
TQString line = s.readLine();
while (!line.isNull())
{
if (line.startsWith("XDG_DOWNLOAD_DIR="))
download = line.remove("XDG_DOWNLOAD_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
else if (line.startsWith("XDG_MUSIC_DIR="))
music = line.remove("XDG_MUSIC_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
else if (line.startsWith("XDG_PICTURES_DIR="))
pictures = line.remove("XDG_PICTURES_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
else if (line.startsWith("XDG_VIDEOS_DIR="))
videos = line.remove("XDG_VIDEOS_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
else if (line.startsWith("XDG_TEMPLATES_DIR="))
templates = line.remove("XDG_TEMPLATES_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
else if (line.startsWith("XDG_PUBLICSHARES_DIR="))
publicShares = line.remove("XDG_PUBLICSHARES_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
line = s.readLine();
}
// now add in the speedbar
if (!download.isEmpty())
insertItem( download, i18n( "Downloads" ), false, "folder_html" );
if (!music.isEmpty())
insertItem( music, i18n( "Music" ), false, "folder_sound" );
if (!pictures.isEmpty())
insertItem( pictures, i18n( "Pictures" ), false, "folder_image" );
if (!videos.isEmpty())
insertItem( videos, i18n( "Videos" ), false, "folder_video" );
if (!templates.isEmpty())
insertItem( templates, i18n( "Templates" ), false, "folder_video" );
if (!publicShares.isEmpty())
insertItem( publicShares, i18n( "Public" ), false, "folder_video" );
}
insertItem( u, i18n("Storage Media"), false, KProtocolInfo::icon( "media" ) );
// now add in the speedbar
insertItem(TDEGlobalSettings::downloadPath(), i18n( "Downloads" ), false, "folder_html" );
insertItem(TDEGlobalSettings::musicPath(), i18n( "Music" ), false, "folder_sound" );
insertItem(TDEGlobalSettings::picturesPath(), i18n( "Pictures" ), false, "folder_image" );
insertItem(TDEGlobalSettings::publicSharePath(), i18n( "Public" ), false, "folder" );
insertItem(TDEGlobalSettings::templatesPath(), i18n( "Templates" ), false, "folder" );
insertItem(TDEGlobalSettings::videosPath(), i18n( "Videos" ), false, "folder_video" );
u = "remote:/";
if ( KProtocolInfo::isKnownProtocol( u ) )

Cargando…
Cancelar
Guardar