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     }
00034 
00035     bool showPreviewsInFileTips;
00036 };
00037 
00038 //static
00039 KonqFMSettings * KonqFMSettings::s_pSettings = 0L;
00040 
00041 //static
00042 KonqFMSettings * KonqFMSettings::settings()
00043 {
00044   if (!s_pSettings)
00045   {
00046     KConfig *config = KGlobal::config();
00047     KConfigGroupSaver cgs(config, "FMSettings");
00048     s_pSettings = new KonqFMSettings(config);
00049   }
00050   return s_pSettings;
00051 }
00052 
00053 //static
00054 void KonqFMSettings::reparseConfiguration()
00055 {
00056   if (s_pSettings)
00057   {
00058     KConfig *config = KGlobal::config();
00059     KConfigGroupSaver cgs(config, "FMSettings");
00060     s_pSettings->init( config );
00061   }
00062 }
00063 
00064 KonqFMSettings::KonqFMSettings( KConfig * config )
00065 {
00066   d = new KonqFMSettingsPrivate;
00067   init( config );
00068 }
00069 
00070 KonqFMSettings::~KonqFMSettings()
00071 {
00072   delete d;
00073 }
00074 
00075 void KonqFMSettings::init( KConfig * config )
00076 {
00077   // Fonts and colors
00078   m_standardFont = config->readFontEntry( "StandardFont" );
00079 
00080   m_normalTextColor = KGlobalSettings::textColor();
00081   m_normalTextColor = config->readColorEntry( "NormalTextColor", &m_normalTextColor );
00082   m_highlightedTextColor = KGlobalSettings::highlightedTextColor();
00083   m_highlightedTextColor = config->readColorEntry( "HighlightedTextColor", &m_highlightedTextColor );
00084   m_itemTextBackground = config->readColorEntry( "ItemTextBackground" );
00085   m_bWordWrapText = config->readBoolEntry( "WordWrapText", DEFAULT_WORDWRAPTEXT );
00086   m_underlineLink = config->readBoolEntry( "UnderlineLinks", DEFAULT_UNDERLINELINKS );
00087   m_fileSizeInBytes = config->readBoolEntry( "DisplayFileSizeInBytes", DEFAULT_FILESIZEINBYTES );
00088   m_iconTransparency = config->readNumEntry( "TextpreviewIconOpacity", DEFAULT_TEXTPREVIEW_ICONTRANSPARENCY );
00089   if ( m_iconTransparency < 0 || m_iconTransparency > 255 )
00090       m_iconTransparency = DEFAULT_TEXTPREVIEW_ICONTRANSPARENCY;
00091 
00092   // Behaviour
00093   m_alwaysNewWin = config->readBoolEntry( "AlwaysNewWin", FALSE );
00094 
00095   m_homeURL = config->readPathEntry("HomeURL", "~");
00096 
00097   m_showFileTips = config->readBoolEntry("ShowFileTips", true);
00098   d->showPreviewsInFileTips = config->readBoolEntry("ShowPreviewsInFileTips", true);
00099   m_numFileTips = config->readNumEntry("FileTipsItems", 6);
00100 
00101   m_embedMap = config->entryMap( "EmbedSettings" );
00102 }
00103 
00104 bool KonqFMSettings::shouldEmbed( const QString & serviceType ) const
00105 {
00106     // First check in user's settings whether to embed or not
00107     // 1 - in the mimetype file itself
00108     KServiceType::Ptr serviceTypePtr = KServiceType::serviceType( serviceType );
00109 
00110     if ( serviceTypePtr )
00111     {
00112         kdDebug(1203) << serviceTypePtr->desktopEntryPath() << endl;
00113         KDesktopFile deFile( serviceTypePtr->desktopEntryPath(),
00114                              true /*readonly*/, "mime");
00115         if ( deFile.hasKey( "X-KDE-AutoEmbed" ) )
00116         {
00117             bool autoEmbed = deFile.readBoolEntry( "X-KDE-AutoEmbed" );
00118             kdDebug(1203) << "X-KDE-AutoEmbed set to " << (autoEmbed ? "true" : "false") << endl;
00119             return autoEmbed;
00120         } else
00121             kdDebug(1203) << "No X-KDE-AutoEmbed, looking for group" << endl;
00122     }
00123     // 2 - in the configuration for the group if nothing was found in the mimetype
00124     QString serviceTypeGroup = serviceType.left(serviceType.find("/"));
00125     kdDebug(1203) << "KonqFMSettings::shouldEmbed : serviceTypeGroup=" << serviceTypeGroup << endl;
00126     if ( serviceTypeGroup == "inode" || serviceTypeGroup == "Browser" || serviceTypeGroup == "Konqueror" )
00127         return true; //always embed mimetype inode/*, Browser/* and Konqueror/*
00128     QMap<QString, QString>::ConstIterator it = m_embedMap.find( QString::fromLatin1("embed-")+serviceTypeGroup );
00129     if ( it == m_embedMap.end() )
00130         return (serviceTypeGroup=="image"); // embedding is false by default except for image/*
00131     // Note: if you change the above default, also change kcontrol/filetypes/typeslistitem.cpp !
00132     kdDebug(1203) << "KonqFMSettings::shouldEmbed: " << it.data() << endl;
00133     return it.data() == QString::fromLatin1("true");
00134 }
00135 
00136 bool KonqFMSettings::showPreviewsInFileTips() const
00137 {
00138     return d->showPreviewsInFileTips;
00139 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Thu Jan 29 23:03:28 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001