Fix Documents shortcut in K Menu and system:/ folder

git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1178867 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
v3.5.13-sru
tpearson 14 years ago
parent 6ade341229
commit 0dfb53e20e

@ -1,6 +1,6 @@
[Desktop Entry]
Type=Link
Path[$e]=$( kxdglauncher --getpath --xdgname DOCUMENTS )
Path=$( kxdglauncher --getpath --xdgname DOCUMENTS )
Icon=folder_man
Name=Documents Folder
Name[af]=Dokument Gids

@ -27,6 +27,7 @@
#include <tqapplication.h>
#include <tqeventloop.h>
#include <tqdir.h>
#include <tqfile.h>
#include <sys/stat.h>
@ -206,6 +207,33 @@ void SystemImpl::createTopLevelEntry(KIO::UDSEntry &entry) const
addAtom(entry, KIO::UDS_ICON_NAME, 0, "system");
}
TQString SystemImpl::readPathINL(TQString filename)
{
bool isPathExpanded = false;
TQString unexpandedPath;
TQFile f( filename );
if (!f.open(IO_ReadOnly))
return TQString();
// set the codec for the current locale
TQTextStream s(&f);
TQString line = s.readLine();
while (!line.isNull())
{
if (line.startsWith("Path=$(")) {
isPathExpanded = true;
unexpandedPath = line.remove("Path=");
}
line = s.readLine();
}
if (isPathExpanded == false) {
KDesktopFile desktop(filename, true);
return desktop.readPath();
}
else {
return unexpandedPath;
}
}
void SystemImpl::createEntry(KIO::UDSEntry &entry,
const TQString &directory,
const TQString &file)
@ -219,7 +247,7 @@ void SystemImpl::createEntry(KIO::UDSEntry &entry,
entry.clear();
// Ensure that we really want this entry to be displayed
if ( desktop.readURL().isEmpty() && desktop.readPath().isEmpty() )
if ( desktop.readURL().isEmpty() && readPathINL(directory+file).isEmpty() )
{
return;
}
@ -231,7 +259,7 @@ void SystemImpl::createEntry(KIO::UDSEntry &entry,
if ( desktop.readURL().isEmpty() )
{
addAtom(entry, KIO::UDS_URL, 0, desktop.readPath());
addAtom(entry, KIO::UDS_URL, 0, readPathINL(directory+file));
}
else
{

@ -22,6 +22,7 @@
#include <kio/global.h>
#include <kio/job.h>
#include <kdesktopfile.h>
#include <kurl.h>
#include <dcopobject.h>
@ -56,6 +57,8 @@ private:
bool m_lastListingEmpty;
TQString readPathINL(TQString filename);
/// Last error code stored in class to simplify API.
/// Note that this means almost no method can be const.
int m_lastErrorCode;

@ -485,6 +485,69 @@ void KonqMainWindow::openURL( KonqView *_view, const KURL &_url,
#endif
KURL url( _url );
if (url.url().startsWith("$(")) {
// check for environment variables and make necessary translations
TQString aValue = url.url();
int nDollarPos = aValue.find( '$' );
while( nDollarPos != -1 && nDollarPos+1 < static_cast<int>(aValue.length())) {
// there is at least one $
if( (aValue)[nDollarPos+1] == '(' ) {
uint nEndPos = nDollarPos+1;
// the next character is no $
while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!=')') )
nEndPos++;
nEndPos++;
TQString cmd = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
TQString result;
FILE *fs = popen(TQFile::encodeName(cmd).data(), "r");
if (fs)
{
{
TQTextStream ts(fs, IO_ReadOnly);
result = ts.read().stripWhiteSpace();
}
pclose(fs);
}
aValue.replace( nDollarPos, nEndPos-nDollarPos, result );
} else if( (aValue)[nDollarPos+1] != '$' ) {
uint nEndPos = nDollarPos+1;
// the next character is no $
TQString aVarName;
if (aValue[nEndPos]=='{')
{
while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!='}') )
nEndPos++;
nEndPos++;
aVarName = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
}
else
{
while ( nEndPos <= aValue.length() && (aValue[nEndPos].isNumber()
|| aValue[nEndPos].isLetter() || aValue[nEndPos]=='_' ) )
nEndPos++;
aVarName = aValue.mid( nDollarPos+1, nEndPos-nDollarPos-1 );
}
const char* pEnv = 0;
if (!aVarName.isEmpty())
pEnv = getenv( aVarName.ascii() );
if( pEnv ) {
// !!! Sergey A. Sukiyazov <corwin@micom.don.ru> !!!
// A environment variables may contain values in 8bit
// locale cpecified encoding or in UTF8 encoding.
aValue.replace( nDollarPos, nEndPos-nDollarPos, KStringHandler::from8Bit( pEnv ) );
} else
aValue.remove( nDollarPos, nEndPos-nDollarPos );
} else {
// remove one of the dollar signs
aValue.remove( nDollarPos, 1 );
nDollarPos++;
}
nDollarPos = aValue.find( '$', nDollarPos );
}
url = KURL(aValue);
}
TQString serviceType( _serviceType );
if ( url.url() == "about:blank" )
{

Loading…
Cancel
Save