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., 51 Franklin Street, Fifth Floor,
00016     Boston, MA 02110-1301, 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 #include <kdesktopfile.h>
00032 
00033 KFileSpeedBar::KFileSpeedBar( QWidget *parent, const char *name )
00034     : KURLBar( true, parent, name )
00035 {
00036     KConfig *config = KGlobal::config();
00037     KConfigGroupSaver cs( config, ConfigGroup );
00038     m_initializeSpeedbar = config->readBoolEntry( "Set speedbar defaults",
00039                                                    true );
00040     setIconSize(KIcon::SizeSmallMedium);
00041     readConfig( KGlobal::config(), "KFileDialog Speedbar" );
00042 
00043     if ( m_initializeSpeedbar )
00044     {
00045         KURL u;
00046         u.setPath( KGlobalSettings::desktopPath() );
00047         insertItem( u, i18n("Desktop"), false );
00048 
00049 //TODO: win32
00050         if ((KGlobalSettings::documentPath() != (QDir::homeDirPath()+"/")) &&
00051             QDir(KGlobalSettings::documentPath()).exists())
00052         {
00053             u.setPath( KGlobalSettings::documentPath() );
00054             insertItem( u, i18n("Documents"), false, "document" );
00055         }
00056 
00057         u.setPath( QDir::homeDirPath() );
00058         insertItem( u, i18n("Home Folder"), false,
00059                                "folder_home" );
00060 
00061         u = "media:/";
00062         if ( KProtocolInfo::isKnownProtocol( u ) )
00063             insertItem( u, i18n("Storage Media"), false,
00064                                    KProtocolInfo::icon( "media" ) );
00065 
00066         u = "remote:/";
00067         if ( KProtocolInfo::isKnownProtocol( u ) )
00068             insertItem( u, i18n("Network Folders"), false,
00069                                    KProtocolInfo::icon( "remote" ) );
00070         QDir homeDir(QDir::homeDirPath()+"/.mdk-folders/");
00071         if( homeDir.exists())
00072         {
00073             QStringList listDesktopFile = homeDir.entryList ( "*-mdk.desktop");
00074             QStringList::Iterator end(listDesktopFile.end());
00075             listDesktopFile.remove("documents-mdk.desktop");
00076             listDesktopFile.remove("desktop-mdk.desktop");
00077             for ( QStringList::Iterator it = listDesktopFile.begin(); it != end; ++it ) 
00078             {
00079                 KDesktopFile tmpFile(homeDir.path ()+"/"+*it);
00080                 QString url = tmpFile.readURL();
00081                 QString icon = tmpFile.readIcon();
00082                 QString name = tmpFile.readName();
00083                 insertItem( url, name, false, icon );
00084             }
00085         }
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 Home | KDE Accessibility Home | Description of Access Keys