You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
185 lines
6.5 KiB
185 lines
6.5 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 1999 David Faure <faure@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "konq_settings.h"
|
||
|
#include "konq_defaults.h"
|
||
12 years ago
|
#include "tdeglobalsettings.h"
|
||
|
#include <tdeglobal.h>
|
||
15 years ago
|
#include <kservicetype.h>
|
||
|
#include <kdesktopfile.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <assert.h>
|
||
15 years ago
|
#include <tqfontmetrics.h>
|
||
15 years ago
|
|
||
|
struct KonqFMSettingsPrivate
|
||
|
{
|
||
|
KonqFMSettingsPrivate() {
|
||
|
showPreviewsInFileTips = true;
|
||
|
m_renameIconDirectly = false;
|
||
|
}
|
||
|
|
||
|
bool showPreviewsInFileTips;
|
||
|
bool m_renameIconDirectly;
|
||
|
bool localeAwareCompareIsCaseSensitive;
|
||
|
int m_iconTextWidth;
|
||
|
};
|
||
|
|
||
|
//static
|
||
|
KonqFMSettings * KonqFMSettings::s_pSettings = 0L;
|
||
|
|
||
|
//static
|
||
|
KonqFMSettings * KonqFMSettings::settings()
|
||
|
{
|
||
|
if (!s_pSettings)
|
||
|
{
|
||
12 years ago
|
TDEConfig *config = TDEGlobal::config();
|
||
|
TDEConfigGroupSaver cgs(config, "FMSettings");
|
||
15 years ago
|
s_pSettings = new KonqFMSettings(config);
|
||
|
}
|
||
|
return s_pSettings;
|
||
|
}
|
||
|
|
||
|
//static
|
||
|
void KonqFMSettings::reparseConfiguration()
|
||
|
{
|
||
|
if (s_pSettings)
|
||
|
{
|
||
12 years ago
|
TDEConfig *config = TDEGlobal::config();
|
||
|
TDEConfigGroupSaver cgs(config, "FMSettings");
|
||
15 years ago
|
s_pSettings->init( config );
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
KonqFMSettings::KonqFMSettings( TDEConfig * config )
|
||
15 years ago
|
{
|
||
|
d = new KonqFMSettingsPrivate;
|
||
|
init( config );
|
||
|
}
|
||
|
|
||
|
KonqFMSettings::~KonqFMSettings()
|
||
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
12 years ago
|
void KonqFMSettings::init( TDEConfig * config )
|
||
15 years ago
|
{
|
||
|
// Fonts and colors
|
||
|
m_standardFont = config->readFontEntry( "StandardFont" );
|
||
|
|
||
12 years ago
|
m_normalTextColor = TDEGlobalSettings::textColor();
|
||
15 years ago
|
m_normalTextColor = config->readColorEntry( "NormalTextColor", &m_normalTextColor );
|
||
12 years ago
|
m_highlightedTextColor = TDEGlobalSettings::highlightedTextColor();
|
||
15 years ago
|
m_highlightedTextColor = config->readColorEntry( "HighlightedTextColor", &m_highlightedTextColor );
|
||
|
m_itemTextBackground = config->readColorEntry( "ItemTextBackground" );
|
||
|
|
||
|
d->m_iconTextWidth = config->readNumEntry( "TextWidth", DEFAULT_TEXTWIDTH );
|
||
|
if ( d->m_iconTextWidth == DEFAULT_TEXTWIDTH )
|
||
15 years ago
|
d->m_iconTextWidth = TQFontMetrics(m_standardFont).width("0000000000");
|
||
15 years ago
|
|
||
|
m_iconTextHeight = config->readNumEntry( "TextHeight", 0 );
|
||
|
if ( m_iconTextHeight == 0 ) {
|
||
|
if ( config->readBoolEntry( "WordWrapText", true ) )
|
||
|
m_iconTextHeight = DEFAULT_TEXTHEIGHT;
|
||
|
else
|
||
|
m_iconTextHeight = 1;
|
||
|
}
|
||
|
m_bWordWrapText = ( m_iconTextHeight > 1 );
|
||
|
|
||
|
m_underlineLink = config->readBoolEntry( "UnderlineLinks", DEFAULT_UNDERLINELINKS );
|
||
|
d->m_renameIconDirectly = config->readBoolEntry( "RenameIconDirectly", DEFAULT_RENAMEICONDIRECTLY );
|
||
|
m_fileSizeInBytes = config->readBoolEntry( "DisplayFileSizeInBytes", DEFAULT_FILESIZEINBYTES );
|
||
|
m_iconTransparency = config->readNumEntry( "TextpreviewIconOpacity", DEFAULT_TEXTPREVIEW_ICONTRANSPARENCY );
|
||
|
if ( m_iconTransparency < 0 || m_iconTransparency > 255 )
|
||
|
m_iconTransparency = DEFAULT_TEXTPREVIEW_ICONTRANSPARENCY;
|
||
|
|
||
|
// Behaviour
|
||
|
m_alwaysNewWin = config->readBoolEntry( "AlwaysNewWin", FALSE );
|
||
|
|
||
|
m_homeURL = config->readPathEntry("HomeURL", "~");
|
||
|
|
||
|
m_showFileTips = config->readBoolEntry("ShowFileTips", true);
|
||
|
d->showPreviewsInFileTips = config->readBoolEntry("ShowPreviewsInFileTips", true);
|
||
|
m_numFileTips = config->readNumEntry("FileTipsItems", 6);
|
||
|
|
||
|
m_embedMap = config->entryMap( "EmbedSettings" );
|
||
|
|
||
15 years ago
|
/// true if TQString::localeAwareCompare is case sensitive (it usually isn't, when LC_COLLATE is set)
|
||
|
d->localeAwareCompareIsCaseSensitive = TQString( "a" ).localeAwareCompare( "B" ) > 0; // see #40131
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
bool KonqFMSettings::shouldEmbed( const TQString & serviceType ) const
|
||
15 years ago
|
{
|
||
|
// First check in user's settings whether to embed or not
|
||
|
// 1 - in the mimetype file itself
|
||
|
KServiceType::Ptr serviceTypePtr = KServiceType::serviceType( serviceType );
|
||
|
bool hasLocalProtocolRedirect = false;
|
||
|
if ( serviceTypePtr )
|
||
|
{
|
||
13 years ago
|
hasLocalProtocolRedirect = !serviceTypePtr->property( "X-TDE-LocalProtocol" ).toString().isEmpty();
|
||
|
TQVariant autoEmbedProp = serviceTypePtr->property( "X-TDE-AutoEmbed" );
|
||
15 years ago
|
if ( autoEmbedProp.isValid() )
|
||
|
{
|
||
|
bool autoEmbed = autoEmbedProp.toBool();
|
||
13 years ago
|
kdDebug(1203) << "X-TDE-AutoEmbed set to " << (autoEmbed ? "true" : "false") << endl;
|
||
15 years ago
|
return autoEmbed;
|
||
|
} else
|
||
13 years ago
|
kdDebug(1203) << "No X-TDE-AutoEmbed, looking for group" << endl;
|
||
15 years ago
|
}
|
||
|
// 2 - in the configuration for the group if nothing was found in the mimetype
|
||
13 years ago
|
TQString serviceTypeGroup = serviceType.left(serviceType.find("/"));
|
||
15 years ago
|
kdDebug(1203) << "KonqFMSettings::shouldEmbed : serviceTypeGroup=" << serviceTypeGroup << endl;
|
||
|
if ( serviceTypeGroup == "inode" || serviceTypeGroup == "Browser" || serviceTypeGroup == "Konqueror" )
|
||
|
return true; //always embed mimetype inode/*, Browser/* and Konqueror/*
|
||
13 years ago
|
TQMap<TQString, TQString>::ConstIterator it = m_embedMap.find( TQString::fromLatin1("embed-")+serviceTypeGroup );
|
||
15 years ago
|
if ( it != m_embedMap.end() ) {
|
||
|
kdDebug(1203) << "KonqFMSettings::shouldEmbed: " << it.data() << endl;
|
||
13 years ago
|
return it.data() == TQString::fromLatin1("true");
|
||
15 years ago
|
}
|
||
|
// 3 - if no config found, use default.
|
||
|
// Note: if you change those defaults, also change kcontrol/filetypes/typeslistitem.cpp !
|
||
|
// Embedding is false by default except for image/* and for zip, tar etc.
|
||
|
if ( serviceTypeGroup == "image" || hasLocalProtocolRedirect )
|
||
|
return true;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
bool KonqFMSettings::showPreviewsInFileTips() const
|
||
|
{
|
||
|
return d->showPreviewsInFileTips;
|
||
|
}
|
||
|
|
||
|
bool KonqFMSettings::renameIconDirectly() const
|
||
|
{
|
||
|
return d->m_renameIconDirectly;
|
||
|
}
|
||
|
|
||
15 years ago
|
int KonqFMSettings::caseSensitiveCompare( const TQString& a, const TQString& b ) const
|
||
15 years ago
|
{
|
||
|
if ( d->localeAwareCompareIsCaseSensitive ) {
|
||
|
return a.localeAwareCompare( b );
|
||
|
}
|
||
15 years ago
|
else // can't use localeAwareCompare, have to fallback to normal TQString compare
|
||
15 years ago
|
return a.compare( b );
|
||
|
}
|
||
|
|
||
|
int KonqFMSettings::iconTextWidth() const
|
||
|
{
|
||
|
return d->m_iconTextWidth;
|
||
|
}
|