You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
5.2 KiB
148 lines
5.2 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org>
|
||
|
|
||
|
library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation, version 2.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
12 years ago
|
#include "tdefilespeedbar.h"
|
||
|
#include "config-tdefile.h"
|
||
15 years ago
|
|
||
15 years ago
|
#include <tqdir.h>
|
||
|
#include <tqfile.h>
|
||
13 years ago
|
#include <tqtextcodec.h>
|
||
|
#include <tqtextstream.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
15 years ago
|
#include <kglobal.h>
|
||
|
#include <kglobalsettings.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kprotocolinfo.h>
|
||
|
#include <kstandarddirs.h>
|
||
|
#include <kurl.h>
|
||
|
|
||
15 years ago
|
KFileSpeedBar::KFileSpeedBar( TQWidget *parent, const char *name )
|
||
15 years ago
|
: KURLBar( true, parent, name )
|
||
|
{
|
||
12 years ago
|
TDEConfig *config = TDEGlobal::config();
|
||
|
TDEConfigGroupSaver cs( config, ConfigGroup );
|
||
15 years ago
|
m_initializeSpeedbar = config->readBoolEntry( "Set speedbar defaults",
|
||
|
true );
|
||
|
setIconSize(KIcon::SizeSmallMedium);
|
||
12 years ago
|
readConfig( TDEGlobal::config(), "KFileDialog Speedbar" );
|
||
15 years ago
|
|
||
|
if ( m_initializeSpeedbar )
|
||
|
{
|
||
|
KURL u;
|
||
12 years ago
|
u.setPath( TDEGlobalSettings::desktopPath() );
|
||
15 years ago
|
insertItem( u, i18n("Desktop"), false );
|
||
|
|
||
|
//TODO: win32
|
||
12 years ago
|
if ((TDEGlobalSettings::documentPath() != (TQDir::homeDirPath()+"/")) &&
|
||
|
TQDir(TDEGlobalSettings::documentPath()).exists())
|
||
15 years ago
|
{
|
||
12 years ago
|
u.setPath( TDEGlobalSettings::documentPath() );
|
||
15 years ago
|
insertItem( u, i18n("Documents"), false, "folder_txt" );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
u.setPath( TQDir::homeDirPath() );
|
||
15 years ago
|
insertItem( u, i18n("Home Folder"), false,
|
||
|
"folder_home" );
|
||
|
|
||
|
u = "media:/";
|
||
|
if ( KProtocolInfo::isKnownProtocol( u ) )
|
||
|
insertItem( u, i18n("Storage Media"), false,
|
||
|
KProtocolInfo::icon( "media" ) );
|
||
|
|
||
15 years ago
|
if ( TQFile::exists( TQDir::homeDirPath()+"/.config/user-dirs.dirs" ) )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString download, music, pictures, videos, templates, publicShares;
|
||
15 years ago
|
|
||
15 years ago
|
TQFile f( TQDir::homeDirPath()+"/.config/user-dirs.dirs" );
|
||
15 years ago
|
if (!f.open(IO_ReadOnly))
|
||
|
return;
|
||
|
|
||
15 years ago
|
TQTextStream s( &f );
|
||
|
s.setCodec( TQTextCodec::codecForLocale() );
|
||
15 years ago
|
|
||
|
// read the xdg user dirs
|
||
15 years ago
|
TQString line = s.readLine();
|
||
15 years ago
|
while (!line.isNull())
|
||
|
{
|
||
|
if (line.startsWith("XDG_DOWNLOAD_DIR="))
|
||
14 years ago
|
download = line.remove("XDG_DOWNLOAD_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
|
||
15 years ago
|
else if (line.startsWith("XDG_MUSIC_DIR="))
|
||
14 years ago
|
music = line.remove("XDG_MUSIC_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
|
||
15 years ago
|
else if (line.startsWith("XDG_PICTURES_DIR="))
|
||
14 years ago
|
pictures = line.remove("XDG_PICTURES_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
|
||
15 years ago
|
else if (line.startsWith("XDG_VIDEOS_DIR="))
|
||
14 years ago
|
videos = line.remove("XDG_VIDEOS_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
|
||
15 years ago
|
else if (line.startsWith("XDG_TEMPLATES_DIR="))
|
||
14 years ago
|
templates = line.remove("XDG_TEMPLATES_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
|
||
15 years ago
|
else if (line.startsWith("XDG_PUBLICSHARES_DIR="))
|
||
14 years ago
|
publicShares = line.remove("XDG_PUBLICSHARES_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
|
||
15 years ago
|
|
||
|
line = s.readLine();
|
||
|
}
|
||
|
// now add in the speedbar
|
||
|
if (!download.isEmpty())
|
||
|
insertItem( download, i18n( "Download" ), 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" );
|
||
|
}
|
||
|
|
||
15 years ago
|
u = "remote:/";
|
||
|
if ( KProtocolInfo::isKnownProtocol( u ) )
|
||
|
insertItem( u, i18n("Network Folders"), false,
|
||
|
KProtocolInfo::icon( "remote" ) );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
KFileSpeedBar::~KFileSpeedBar()
|
||
|
{
|
||
|
}
|
||
|
|
||
12 years ago
|
void KFileSpeedBar::save( TDEConfig *config )
|
||
15 years ago
|
{
|
||
|
if ( m_initializeSpeedbar && isModified() )
|
||
|
{
|
||
12 years ago
|
TDEConfigGroup conf( config, ConfigGroup );
|
||
15 years ago
|
// write to kdeglobals
|
||
|
conf.writeEntry( "Set speedbar defaults", false, true, true );
|
||
|
}
|
||
|
|
||
|
writeConfig( config, "KFileDialog Speedbar" );
|
||
|
}
|
||
|
|
||
13 years ago
|
TQSize KFileSpeedBar::sizeHint() const
|
||
15 years ago
|
{
|
||
13 years ago
|
TQSize sizeHint = KURLBar::sizeHint();
|
||
15 years ago
|
int ems = fontMetrics().width("mmmmmmmmmmmm");
|
||
13 years ago
|
if (sizeHint.width() < ems)
|
||
15 years ago
|
{
|
||
13 years ago
|
sizeHint.setWidth(ems);
|
||
15 years ago
|
}
|
||
13 years ago
|
return sizeHint;
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
#include "tdefilespeedbar.moc"
|