kio Library API Documentation

kfilespeedbar.cpp

00001 /* This file is part of the KDE libraries
00002     Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org>
00003 
00004     library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation, version 2.
00007 
00008     This library is distributed in the hope that it will be useful,
00009     but WITHOUT ANY WARRANTY; without even the implied warranty of
00010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011     Library General Public License for more details.
00012 
00013     You should have received a copy of the GNU Library General Public License
00014     along with this library; see the file COPYING.LIB.  If not, write to
00015     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00016     Boston, MA 02111-1307, USA.
00017 */
00018 
00019 #include "kfilespeedbar.h"
00020 #include "config-kfile.h"
00021 
00022 #include <qdir.h>
00023 
00024 #include <kconfig.h>
00025 #include <kglobal.h>
00026 #include <kglobalsettings.h>
00027 #include <klocale.h>
00028 #include <kprotocolinfo.h>
00029 #include <kstandarddirs.h>
00030 #include <kurl.h>
00031 
00032 KFileSpeedBar::KFileSpeedBar( QWidget *parent, const char *name )
00033     : KURLBar( true, parent, name )
00034 {
00035     KConfig *config = KGlobal::config();
00036     KConfigGroupSaver cs( config, ConfigGroup );
00037     m_initializeSpeedbar = config->readBoolEntry( "Set speedbar defaults",
00038                                                    true );
00039     setIconSize(KIcon::SizeSmallMedium);
00040     readConfig( KGlobal::config(), "KFileDialog Speedbar" );
00041 
00042     if ( m_initializeSpeedbar )
00043     {
00044         KURL u;
00045         u.setPath( KGlobalSettings::desktopPath() );
00046         insertItem( u, i18n("Desktop"), false );
00047 
00048         if ((KGlobalSettings::documentPath() != (QDir::homeDirPath()+"/")) &&
00049             QDir(KGlobalSettings::documentPath()).exists())
00050         {
00051             u.setPath( KGlobalSettings::documentPath() );
00052             insertItem( u, i18n("Documents"), false, "document" );
00053         }
00054 
00055         u.setPath( QDir::homeDirPath() );
00056         insertItem( u, i18n("Home Folder"), false,
00057                                "folder_home" );
00058 
00059         u.setPath( QString("/mnt/cdrom") );
00060         insertItem( u, i18n("Cdrom"), false,
00061                                "cdrom_mount" );
00062 
00063         u = "floppy:/";
00064         if ( KProtocolInfo::isKnownProtocol( u ) )
00065         {
00066             u.setPath( QString("/mnt/floppy") );
00067             insertItem( u, i18n("Floppy"), false,
00068                                "3floppy_mount" );
00069         }
00070 
00071         u = "devices:/";
00072         if ( KProtocolInfo::isKnownProtocol( u ) )
00073             insertItem( u, i18n("Devices"), false,
00074                                    KProtocolInfo::icon( "devices" ) );
00075 #if 0
00076         QStringList tmpDirs = KGlobal::dirs()->resourceDirs( "tmp" );
00077         u.setProtocol( "file" );
00078         u.setPath( tmpDirs.isEmpty() ? QString("/tmp") : tmpDirs.first() );
00079         insertItem( u, i18n("Temporary Files"), false,
00080                                "file_temporary" );
00081 #endif
00082         u = "lan:/";
00083         if ( KProtocolInfo::isKnownProtocol( u ) )
00084             insertItem( u, i18n("Network"), false,
00085                                    "network_local" );
00086     }
00087 }
00088 
00089 KFileSpeedBar::~KFileSpeedBar()
00090 {
00091 }
00092 
00093 void KFileSpeedBar::save( KConfig *config )
00094 {
00095     if ( m_initializeSpeedbar && isModified() )
00096     {
00097         KConfigGroup conf( config, ConfigGroup );
00098         // write to kdeglobals
00099         conf.writeEntry( "Set speedbar defaults", false, true, true );
00100     }
00101 
00102     writeConfig( config, "KFileDialog Speedbar" );
00103 }
00104 
00105 QSize KFileSpeedBar::sizeHint() const
00106 {
00107     QSize sizeHint = KURLBar::sizeHint();
00108     int ems = fontMetrics().width("mmmmmmmmmmmm");
00109     if (sizeHint.width() < ems)
00110     {
00111         sizeHint.setWidth(ems);
00112     }
00113     return sizeHint;
00114 }
00115 
00116 #include "kfilespeedbar.moc"
KDE Logo
This file is part of the documentation for kio Library Version 3.3.90.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 30 10:15:29 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003