1999-10-29 13:32:36 +00:00
|
|
|
/* This file is part of the KDE project
|
|
|
|
Copyright (C) 1999 David Faure <faure@kde.org>
|
1999-11-03 23:52:57 +00:00
|
|
|
|
1999-10-29 13:32:36 +00:00
|
|
|
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.
|
1999-11-03 23:52:57 +00:00
|
|
|
|
1999-10-29 13:32:36 +00:00
|
|
|
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.
|
1999-11-03 23:52:57 +00:00
|
|
|
|
1999-10-29 13:32:36 +00:00
|
|
|
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
|
2005-10-05 08:44:32 +00:00
|
|
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
2005-07-04 19:02:09 +00:00
|
|
|
Boston, MA 02110-1301, USA.
|
1999-11-03 23:52:57 +00:00
|
|
|
*/
|
1999-10-29 13:32:36 +00:00
|
|
|
|
2000-07-27 09:23:48 +00:00
|
|
|
#include "konq_settings.h"
|
|
|
|
#include "konq_defaults.h"
|
2000-04-12 12:46:42 +00:00
|
|
|
#include "kglobalsettings.h"
|
1999-12-08 17:46:09 +00:00
|
|
|
#include <kglobal.h>
|
2000-03-18 00:33:10 +00:00
|
|
|
#include <kservicetype.h>
|
|
|
|
#include <kdesktopfile.h>
|
|
|
|
#include <kdebug.h>
|
1999-11-21 02:16:22 +00:00
|
|
|
#include <assert.h>
|
2005-01-07 19:36:11 +00:00
|
|
|
#include <qfontmetrics.h>
|
1999-10-04 20:36:48 +00:00
|
|
|
|
2002-06-10 10:33:36 +00:00
|
|
|
struct KonqFMSettingsPrivate
|
|
|
|
{
|
|
|
|
KonqFMSettingsPrivate() {
|
|
|
|
showPreviewsInFileTips = true;
|
2003-03-14 15:33:19 +00:00
|
|
|
m_renameIconDirectly = false;
|
2002-06-10 10:33:36 +00:00
|
|
|
}
|
2002-07-26 17:58:46 +00:00
|
|
|
|
2002-06-10 10:33:36 +00:00
|
|
|
bool showPreviewsInFileTips;
|
2003-03-14 15:33:19 +00:00
|
|
|
bool m_renameIconDirectly;
|
2004-02-05 14:59:06 +00:00
|
|
|
bool localeAwareCompareIsCaseSensitive;
|
2004-12-02 16:08:53 +00:00
|
|
|
int m_iconTextWidth;
|
2002-06-10 10:33:36 +00:00
|
|
|
};
|
|
|
|
|
2000-03-18 16:08:31 +00:00
|
|
|
//static
|
|
|
|
KonqFMSettings * KonqFMSettings::s_pSettings = 0L;
|
1999-10-04 20:36:48 +00:00
|
|
|
|
2000-03-18 16:08:31 +00:00
|
|
|
//static
|
|
|
|
KonqFMSettings * KonqFMSettings::settings()
|
1999-10-04 20:36:48 +00:00
|
|
|
{
|
2000-03-18 16:08:31 +00:00
|
|
|
if (!s_pSettings)
|
1999-10-04 20:36:48 +00:00
|
|
|
{
|
1999-12-08 17:46:09 +00:00
|
|
|
KConfig *config = KGlobal::config();
|
2000-03-18 16:08:31 +00:00
|
|
|
KConfigGroupSaver cgs(config, "FMSettings");
|
|
|
|
s_pSettings = new KonqFMSettings(config);
|
1999-10-04 20:36:48 +00:00
|
|
|
}
|
2000-03-18 16:08:31 +00:00
|
|
|
return s_pSettings;
|
1999-10-04 20:36:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
1999-11-20 23:14:02 +00:00
|
|
|
void KonqFMSettings::reparseConfiguration()
|
1999-10-04 20:36:48 +00:00
|
|
|
{
|
2000-03-18 16:08:31 +00:00
|
|
|
if (s_pSettings)
|
1999-10-04 20:36:48 +00:00
|
|
|
{
|
2000-03-18 16:08:31 +00:00
|
|
|
KConfig *config = KGlobal::config();
|
|
|
|
KConfigGroupSaver cgs(config, "FMSettings");
|
|
|
|
s_pSettings->init( config );
|
1999-10-04 20:36:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-20 23:14:02 +00:00
|
|
|
KonqFMSettings::KonqFMSettings( KConfig * config )
|
1999-10-04 20:36:48 +00:00
|
|
|
{
|
2002-06-10 10:33:36 +00:00
|
|
|
d = new KonqFMSettingsPrivate;
|
1999-10-04 20:36:48 +00:00
|
|
|
init( config );
|
|
|
|
}
|
|
|
|
|
2002-06-10 10:33:36 +00:00
|
|
|
KonqFMSettings::~KonqFMSettings()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
1999-11-20 23:14:02 +00:00
|
|
|
void KonqFMSettings::init( KConfig * config )
|
|
|
|
{
|
|
|
|
// Fonts and colors
|
2000-04-18 19:52:28 +00:00
|
|
|
m_standardFont = config->readFontEntry( "StandardFont" );
|
1999-11-20 23:14:02 +00:00
|
|
|
|
2000-06-24 06:08:24 +00:00
|
|
|
m_normalTextColor = KGlobalSettings::textColor();
|
|
|
|
m_normalTextColor = config->readColorEntry( "NormalTextColor", &m_normalTextColor );
|
|
|
|
m_highlightedTextColor = KGlobalSettings::highlightedTextColor();
|
|
|
|
m_highlightedTextColor = config->readColorEntry( "HighlightedTextColor", &m_highlightedTextColor );
|
2000-09-07 15:18:34 +00:00
|
|
|
m_itemTextBackground = config->readColorEntry( "ItemTextBackground" );
|
2004-02-15 01:01:31 +00:00
|
|
|
|
2004-12-02 16:08:53 +00:00
|
|
|
d->m_iconTextWidth = config->readNumEntry( "TextWidth", DEFAULT_TEXTWIDTH );
|
2005-01-07 19:36:11 +00:00
|
|
|
if ( d->m_iconTextWidth == DEFAULT_TEXTWIDTH )
|
|
|
|
d->m_iconTextWidth = QFontMetrics(m_standardFont).width("0000000000");
|
|
|
|
|
2004-02-15 01:01:31 +00:00
|
|
|
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 );
|
|
|
|
|
2000-09-07 15:18:34 +00:00
|
|
|
m_underlineLink = config->readBoolEntry( "UnderlineLinks", DEFAULT_UNDERLINELINKS );
|
2003-03-14 15:33:19 +00:00
|
|
|
d->m_renameIconDirectly = config->readBoolEntry( "RenameIconDirectly", DEFAULT_RENAMEICONDIRECTLY );
|
2001-04-23 17:28:00 +00:00
|
|
|
m_fileSizeInBytes = config->readBoolEntry( "DisplayFileSizeInBytes", DEFAULT_FILESIZEINBYTES );
|
2000-12-02 14:24:02 +00:00
|
|
|
m_iconTransparency = config->readNumEntry( "TextpreviewIconOpacity", DEFAULT_TEXTPREVIEW_ICONTRANSPARENCY );
|
|
|
|
if ( m_iconTransparency < 0 || m_iconTransparency > 255 )
|
|
|
|
m_iconTransparency = DEFAULT_TEXTPREVIEW_ICONTRANSPARENCY;
|
2000-12-12 19:35:54 +00:00
|
|
|
|
2000-03-14 00:27:25 +00:00
|
|
|
// Behaviour
|
1999-12-08 18:20:04 +00:00
|
|
|
m_alwaysNewWin = config->readBoolEntry( "AlwaysNewWin", FALSE );
|
1999-11-20 23:14:02 +00:00
|
|
|
|
2003-06-24 19:46:19 +00:00
|
|
|
m_homeURL = config->readPathEntry("HomeURL", "~");
|
2002-07-26 17:58:46 +00:00
|
|
|
|
2002-01-18 03:31:54 +00:00
|
|
|
m_showFileTips = config->readBoolEntry("ShowFileTips", true);
|
2002-06-10 10:33:36 +00:00
|
|
|
d->showPreviewsInFileTips = config->readBoolEntry("ShowPreviewsInFileTips", true);
|
2002-01-18 03:31:54 +00:00
|
|
|
m_numFileTips = config->readNumEntry("FileTipsItems", 6);
|
1999-12-22 19:58:10 +00:00
|
|
|
|
2000-07-18 18:25:48 +00:00
|
|
|
m_embedMap = config->entryMap( "EmbedSettings" );
|
2004-02-05 14:59:06 +00:00
|
|
|
|
|
|
|
/// true if QString::localeAwareCompare is case sensitive (it usually isn't, when LC_COLLATE is set)
|
|
|
|
d->localeAwareCompareIsCaseSensitive = QString( "a" ).localeAwareCompare( "B" ) > 0; // see #40131
|
1999-12-04 22:45:41 +00:00
|
|
|
}
|
|
|
|
|
2000-05-03 21:55:17 +00:00
|
|
|
bool KonqFMSettings::shouldEmbed( const QString & serviceType ) const
|
1999-12-04 22:45:41 +00:00
|
|
|
{
|
2000-03-18 00:33:10 +00:00
|
|
|
// First check in user's settings whether to embed or not
|
|
|
|
// 1 - in the mimetype file itself
|
|
|
|
KServiceType::Ptr serviceTypePtr = KServiceType::serviceType( serviceType );
|
|
|
|
|
|
|
|
if ( serviceTypePtr )
|
|
|
|
{
|
2000-04-17 13:41:25 +00:00
|
|
|
kdDebug(1203) << serviceTypePtr->desktopEntryPath() << endl;
|
2000-03-18 00:33:10 +00:00
|
|
|
KDesktopFile deFile( serviceTypePtr->desktopEntryPath(),
|
|
|
|
true /*readonly*/, "mime");
|
|
|
|
if ( deFile.hasKey( "X-KDE-AutoEmbed" ) )
|
|
|
|
{
|
|
|
|
bool autoEmbed = deFile.readBoolEntry( "X-KDE-AutoEmbed" );
|
2000-04-17 13:41:25 +00:00
|
|
|
kdDebug(1203) << "X-KDE-AutoEmbed set to " << (autoEmbed ? "true" : "false") << endl;
|
2000-03-18 00:33:10 +00:00
|
|
|
return autoEmbed;
|
|
|
|
} else
|
2000-04-17 13:41:25 +00:00
|
|
|
kdDebug(1203) << "No X-KDE-AutoEmbed, looking for group" << endl;
|
2000-03-18 00:33:10 +00:00
|
|
|
}
|
|
|
|
// 2 - in the configuration for the group if nothing was found in the mimetype
|
|
|
|
QString serviceTypeGroup = serviceType.left(serviceType.find("/"));
|
2000-12-12 19:35:54 +00:00
|
|
|
kdDebug(1203) << "KonqFMSettings::shouldEmbed : serviceTypeGroup=" << serviceTypeGroup << endl;
|
2002-07-31 14:47:03 +00:00
|
|
|
if ( serviceTypeGroup == "inode" || serviceTypeGroup == "Browser" || serviceTypeGroup == "Konqueror" )
|
|
|
|
return true; //always embed mimetype inode/*, Browser/* and Konqueror/*
|
2005-09-12 13:14:55 +00:00
|
|
|
QMap<QString, QString>::ConstIterator it = m_embedMap.find( QLatin1String("embed-")+serviceTypeGroup );
|
2000-07-18 18:25:48 +00:00
|
|
|
if ( it == m_embedMap.end() )
|
2002-07-26 21:25:45 +00:00
|
|
|
return (serviceTypeGroup=="image"); // embedding is false by default except for image/*
|
2002-07-29 07:35:53 +00:00
|
|
|
// Note: if you change the above default, also change kcontrol/filetypes/typeslistitem.cpp !
|
2000-12-12 19:35:54 +00:00
|
|
|
kdDebug(1203) << "KonqFMSettings::shouldEmbed: " << it.data() << endl;
|
2005-09-12 13:14:55 +00:00
|
|
|
return it.data() == QLatin1String("true");
|
1999-11-20 23:14:02 +00:00
|
|
|
}
|
2002-06-10 10:33:36 +00:00
|
|
|
|
2002-07-26 17:58:46 +00:00
|
|
|
bool KonqFMSettings::showPreviewsInFileTips() const
|
2002-06-10 10:33:36 +00:00
|
|
|
{
|
|
|
|
return d->showPreviewsInFileTips;
|
|
|
|
}
|
2003-03-14 15:33:19 +00:00
|
|
|
|
|
|
|
bool KonqFMSettings::renameIconDirectly() const
|
|
|
|
{
|
|
|
|
return d->m_renameIconDirectly;
|
|
|
|
}
|
2004-02-05 14:59:06 +00:00
|
|
|
|
|
|
|
int KonqFMSettings::caseSensitiveCompare( const QString& a, const QString& b ) const
|
|
|
|
{
|
|
|
|
if ( d->localeAwareCompareIsCaseSensitive ) {
|
|
|
|
return a.localeAwareCompare( b );
|
|
|
|
}
|
|
|
|
else // can't use localeAwareCompare, have to fallback to normal QString compare
|
|
|
|
return a.compare( b );
|
|
|
|
}
|
2004-12-02 16:08:53 +00:00
|
|
|
|
|
|
|
int KonqFMSettings::iconTextWidth() const
|
|
|
|
{
|
|
|
|
return d->m_iconTextWidth;
|
|
|
|
}
|