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., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, 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 #include <tqfontmetrics.h> 00029 00030 struct KonqFMSettingsPrivate 00031 { 00032 KonqFMSettingsPrivate() { 00033 showPreviewsInFileTips = true; 00034 m_renameIconDirectly = false; 00035 } 00036 00037 bool showPreviewsInFileTips; 00038 bool m_renameIconDirectly; 00039 bool localeAwareCompareIsCaseSensitive; 00040 int m_iconTextWidth; 00041 }; 00042 00043 //static 00044 KonqFMSettings * KonqFMSettings::s_pSettings = 0L; 00045 00046 //static 00047 KonqFMSettings * KonqFMSettings::settings() 00048 { 00049 if (!s_pSettings) 00050 { 00051 KConfig *config = KGlobal::config(); 00052 KConfigGroupSaver cgs(config, "FMSettings"); 00053 s_pSettings = new KonqFMSettings(config); 00054 } 00055 return s_pSettings; 00056 } 00057 00058 //static 00059 void KonqFMSettings::reparseConfiguration() 00060 { 00061 if (s_pSettings) 00062 { 00063 KConfig *config = KGlobal::config(); 00064 KConfigGroupSaver cgs(config, "FMSettings"); 00065 s_pSettings->init( config ); 00066 } 00067 } 00068 00069 KonqFMSettings::KonqFMSettings( KConfig * config ) 00070 { 00071 d = new KonqFMSettingsPrivate; 00072 init( config ); 00073 } 00074 00075 KonqFMSettings::~KonqFMSettings() 00076 { 00077 delete d; 00078 } 00079 00080 void KonqFMSettings::init( KConfig * config ) 00081 { 00082 // Fonts and colors 00083 m_standardFont = config->readFontEntry( "StandardFont" ); 00084 00085 m_normalTextColor = KGlobalSettings::textColor(); 00086 m_normalTextColor = config->readColorEntry( "NormalTextColor", &m_normalTextColor ); 00087 m_highlightedTextColor = KGlobalSettings::highlightedTextColor(); 00088 m_highlightedTextColor = config->readColorEntry( "HighlightedTextColor", &m_highlightedTextColor ); 00089 m_itemTextBackground = config->readColorEntry( "ItemTextBackground" ); 00090 00091 d->m_iconTextWidth = config->readNumEntry( "TextWidth", DEFAULT_TEXTWIDTH ); 00092 if ( d->m_iconTextWidth == DEFAULT_TEXTWIDTH ) 00093 d->m_iconTextWidth = TQFontMetrics(m_standardFont).width("0000000000"); 00094 00095 m_iconTextHeight = config->readNumEntry( "TextHeight", 0 ); 00096 if ( m_iconTextHeight == 0 ) { 00097 if ( config->readBoolEntry( "WordWrapText", true ) ) 00098 m_iconTextHeight = DEFAULT_TEXTHEIGHT; 00099 else 00100 m_iconTextHeight = 1; 00101 } 00102 m_bWordWrapText = ( m_iconTextHeight > 1 ); 00103 00104 m_underlineLink = config->readBoolEntry( "UnderlineLinks", DEFAULT_UNDERLINELINKS ); 00105 d->m_renameIconDirectly = config->readBoolEntry( "RenameIconDirectly", DEFAULT_RENAMEICONDIRECTLY ); 00106 m_fileSizeInBytes = config->readBoolEntry( "DisplayFileSizeInBytes", DEFAULT_FILESIZEINBYTES ); 00107 m_iconTransparency = config->readNumEntry( "TextpreviewIconOpacity", DEFAULT_TEXTPREVIEW_ICONTRANSPARENCY ); 00108 if ( m_iconTransparency < 0 || m_iconTransparency > 255 ) 00109 m_iconTransparency = DEFAULT_TEXTPREVIEW_ICONTRANSPARENCY; 00110 00111 // Behaviour 00112 m_alwaysNewWin = config->readBoolEntry( "AlwaysNewWin", FALSE ); 00113 00114 m_homeURL = config->readPathEntry("HomeURL", "~"); 00115 00116 m_showFileTips = config->readBoolEntry("ShowFileTips", true); 00117 d->showPreviewsInFileTips = config->readBoolEntry("ShowPreviewsInFileTips", true); 00118 m_numFileTips = config->readNumEntry("FileTipsItems", 6); 00119 00120 m_embedMap = config->entryMap( "EmbedSettings" ); 00121 00123 d->localeAwareCompareIsCaseSensitive = TQString( "a" ).localeAwareCompare( "B" ) > 0; // see #40131 00124 } 00125 00126 bool KonqFMSettings::shouldEmbed( const TQString & serviceType ) const 00127 { 00128 // First check in user's settings whether to embed or not 00129 // 1 - in the mimetype file itself 00130 KServiceType::Ptr serviceTypePtr = KServiceType::serviceType( serviceType ); 00131 bool hasLocalProtocolRedirect = false; 00132 if ( serviceTypePtr ) 00133 { 00134 hasLocalProtocolRedirect = !serviceTypePtr->property( "X-KDE-LocalProtocol" ).toString().isEmpty(); 00135 TQVariant autoEmbedProp = serviceTypePtr->property( "X-KDE-AutoEmbed" ); 00136 if ( autoEmbedProp.isValid() ) 00137 { 00138 bool autoEmbed = autoEmbedProp.toBool(); 00139 kdDebug(1203) << "X-KDE-AutoEmbed set to " << (autoEmbed ? "true" : "false") << endl; 00140 return autoEmbed; 00141 } else 00142 kdDebug(1203) << "No X-KDE-AutoEmbed, looking for group" << endl; 00143 } 00144 // 2 - in the configuration for the group if nothing was found in the mimetype 00145 TQString serviceTypeGroup = serviceType.left(serviceType.find("/")); 00146 kdDebug(1203) << "KonqFMSettings::shouldEmbed : serviceTypeGroup=" << serviceTypeGroup << endl; 00147 if ( serviceTypeGroup == "inode" || serviceTypeGroup == "Browser" || serviceTypeGroup == "Konqueror" ) 00148 return true; //always embed mimetype inode/*, Browser/* and Konqueror/* 00149 TQMap<TQString, TQString>::ConstIterator it = m_embedMap.find( TQString::fromLatin1("embed-")+serviceTypeGroup ); 00150 if ( it != m_embedMap.end() ) { 00151 kdDebug(1203) << "KonqFMSettings::shouldEmbed: " << it.data() << endl; 00152 return it.data() == TQString::fromLatin1("true"); 00153 } 00154 // 3 - if no config found, use default. 00155 // Note: if you change those defaults, also change kcontrol/filetypes/typeslistitem.cpp ! 00156 // Embedding is false by default except for image/* and for zip, tar etc. 00157 if ( serviceTypeGroup == "image" || hasLocalProtocolRedirect ) 00158 return true; 00159 return false; 00160 } 00161 00162 bool KonqFMSettings::showPreviewsInFileTips() const 00163 { 00164 return d->showPreviewsInFileTips; 00165 } 00166 00167 bool KonqFMSettings::renameIconDirectly() const 00168 { 00169 return d->m_renameIconDirectly; 00170 } 00171 00172 int KonqFMSettings::caseSensitiveCompare( const TQString& a, const TQString& b ) const 00173 { 00174 if ( d->localeAwareCompareIsCaseSensitive ) { 00175 return a.localeAwareCompare( b ); 00176 } 00177 else // can't use localeAwareCompare, have to fallback to normal TQString compare 00178 return a.compare( b ); 00179 } 00180 00181 int KonqFMSettings::iconTextWidth() const 00182 { 00183 return d->m_iconTextWidth; 00184 }