libkonq Library API Documentation

konq_settings.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 1999 David Faure <faure@kde.org>
00003 
00004    This 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; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #include "konq_settings.h"
00021 #include "konq_defaults.h"
00022 #include "kglobalsettings.h"
00023 #include <kglobal.h>
00024 #include <kservicetype.h>
00025 #include <kdesktopfile.h>
00026 #include <kdebug.h>
00027 #include <assert.h>
00028 
00029 struct KonqFMSettingsPrivate
00030 {
00031     KonqFMSettingsPrivate() {
00032         showPreviewsInFileTips = true;
00033         m_renameIconDirectly = false;
00034     }
00035 
00036     bool showPreviewsInFileTips;
00037     bool m_renameIconDirectly;
00038     bool localeAwareCompareIsCaseSensitive;
00039 };
00040 
00041 //static
00042 KonqFMSettings * KonqFMSettings::s_pSettings = 0L;
00043 
00044 //static
00045 KonqFMSettings * KonqFMSettings::settings()
00046 {
00047   if (!s_pSettings)
00048   {
00049     KConfig *config = KGlobal::config();
00050     KConfigGroupSaver cgs(config, "FMSettings");
00051     s_pSettings = new KonqFMSettings(config);
00052   }
00053   return s_pSettings;
00054 }
00055 
00056 //static
00057 void KonqFMSettings::reparseConfiguration()
00058 {
00059   if (s_pSettings)
00060   {
00061     KConfig *config = KGlobal::config();
00062     KConfigGroupSaver cgs(config, "FMSettings");
00063     s_pSettings->init( config );
00064   }
00065 }
00066 
00067 KonqFMSettings::KonqFMSettings( KConfig * config )
00068 {
00069   d = new KonqFMSettingsPrivate;
00070   init( config );
00071 }
00072 
00073 KonqFMSettings::~KonqFMSettings()
00074 {
00075   delete d;
00076 }
00077 
00078 void KonqFMSettings::init( KConfig * config )
00079 {
00080   // Fonts and colors
00081   m_standardFont = config->readFontEntry( "StandardFont" );
00082 
00083   m_normalTextColor = KGlobalSettings::textColor();
00084   m_normalTextColor = config->readColorEntry( "NormalTextColor", &m_normalTextColor );
00085   m_highlightedTextColor = KGlobalSettings::highlightedTextColor();
00086   m_highlightedTextColor = config->readColorEntry( "HighlightedTextColor", &m_highlightedTextColor );
00087   m_itemTextBackground = config->readColorEntry( "ItemTextBackground" );
00088   
00089   m_iconTextHeight = config->readNumEntry( "TextHeight", 0 );
00090   if ( m_iconTextHeight == 0 ) {
00091     if ( config->readBoolEntry( "WordWrapText", true ) )
00092       m_iconTextHeight = DEFAULT_TEXTHEIGHT;
00093     else
00094       m_iconTextHeight = 1;
00095   }
00096   m_bWordWrapText = ( m_iconTextHeight > 1 );
00097   
00098   m_underlineLink = config->readBoolEntry( "UnderlineLinks", DEFAULT_UNDERLINELINKS );
00099   d->m_renameIconDirectly = config->readBoolEntry( "RenameIconDirectly", DEFAULT_RENAMEICONDIRECTLY );
00100   m_fileSizeInBytes = config->readBoolEntry( "DisplayFileSizeInBytes", DEFAULT_FILESIZEINBYTES );
00101   m_iconTransparency = config->readNumEntry( "TextpreviewIconOpacity", DEFAULT_TEXTPREVIEW_ICONTRANSPARENCY );
00102   if ( m_iconTransparency < 0 || m_iconTransparency > 255 )
00103       m_iconTransparency = DEFAULT_TEXTPREVIEW_ICONTRANSPARENCY;
00104 
00105   // Behaviour
00106   m_alwaysNewWin = config->readBoolEntry( "AlwaysNewWin", FALSE );
00107 
00108   m_homeURL = config->readPathEntry("HomeURL", "~");
00109 
00110   m_showFileTips = config->readBoolEntry("ShowFileTips", false);
00111   d->showPreviewsInFileTips = config->readBoolEntry("ShowPreviewsInFileTips", true);
00112   m_numFileTips = config->readNumEntry("FileTipsItems", 6);
00113 
00114   m_embedMap = config->entryMap( "EmbedSettings" );
00115 
00117   d->localeAwareCompareIsCaseSensitive = QString( "a" ).localeAwareCompare( "B" ) > 0; // see #40131
00118 }
00119 
00120 bool KonqFMSettings::shouldEmbed( const QString & serviceType ) const
00121 {
00122     // First check in user's settings whether to embed or not
00123     // 1 - in the mimetype file itself
00124     KServiceType::Ptr serviceTypePtr = KServiceType::serviceType( serviceType );
00125 
00126     if ( serviceTypePtr )
00127     {
00128         kdDebug(1203) << serviceTypePtr->desktopEntryPath() << endl;
00129         KDesktopFile deFile( serviceTypePtr->desktopEntryPath(),
00130                              true /*readonly*/, "mime");
00131         if ( deFile.hasKey( "X-KDE-AutoEmbed" ) )
00132         {
00133             bool autoEmbed = deFile.readBoolEntry( "X-KDE-AutoEmbed" );
00134             kdDebug(1203) << "X-KDE-AutoEmbed set to " << (autoEmbed ? "true" : "false") << endl;
00135             return autoEmbed;
00136         } else
00137             kdDebug(1203) << "No X-KDE-AutoEmbed, looking for group" << endl;
00138     }
00139     // 2 - in the configuration for the group if nothing was found in the mimetype
00140     QString serviceTypeGroup = serviceType.left(serviceType.find("/"));
00141     kdDebug(1203) << "KonqFMSettings::shouldEmbed : serviceTypeGroup=" << serviceTypeGroup << endl;
00142     if ( serviceTypeGroup == "inode" || serviceTypeGroup == "Browser" || serviceTypeGroup == "Konqueror" )
00143         return true; //always embed mimetype inode/*, Browser/* and Konqueror/*
00144     QMap<QString, QString>::ConstIterator it = m_embedMap.find( QString::fromLatin1("embed-")+serviceTypeGroup );
00145     if ( it == m_embedMap.end() )
00146         return (serviceTypeGroup=="image"); // embedding is false by default except for image/*
00147     // Note: if you change the above default, also change kcontrol/filetypes/typeslistitem.cpp !
00148     kdDebug(1203) << "KonqFMSettings::shouldEmbed: " << it.data() << endl;
00149     return it.data() == QString::fromLatin1("true");
00150 }
00151 
00152 bool KonqFMSettings::showPreviewsInFileTips() const
00153 {
00154     return d->showPreviewsInFileTips;
00155 }
00156 
00157 bool KonqFMSettings::renameIconDirectly() const
00158 {
00159     return d->m_renameIconDirectly;
00160 }
00161 
00162 int KonqFMSettings::caseSensitiveCompare( const QString& a, const QString& b ) const
00163 {
00164     if ( d->localeAwareCompareIsCaseSensitive ) {
00165         return a.localeAwareCompare( b );
00166     }
00167     else // can't use localeAwareCompare, have to fallback to normal QString compare
00168         return a.compare( b );
00169 }
KDE Logo
This file is part of the documentation for libkonq Library Version 3.3.90.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Apr 5 03:59:20 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003