00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "konq_propsview.h"
00021
00022 #include <kdebug.h>
00023 #include <kstandarddirs.h>
00024 #include <kpixmap.h>
00025 #include <qpixmapcache.h>
00026 #include <qiconview.h>
00027 #include <unistd.h>
00028 #include <qfile.h>
00029 #include <iostream>
00030 #include <ktrader.h>
00031 #include <kinstance.h>
00032 #include <assert.h>
00033
00034 #include <ksimpleconfig.h>
00035
00036 static QPixmap wallpaperPixmap( const QString & _wallpaper )
00037 {
00038 QString key = "wallpapers/";
00039 key += _wallpaper;
00040 KPixmap pix;
00041
00042 if ( QPixmapCache::find( key, pix ) )
00043 return pix;
00044
00045 QString path = locate("tiles", _wallpaper);
00046 if (path.isEmpty())
00047 path = locate("wallpaper", _wallpaper);
00048 if (!path.isEmpty())
00049 {
00050
00051
00052
00053
00054 pix.load( path );
00055 if ( pix.isNull() )
00056 kdWarning(1203) << "Could not load wallpaper " << path << endl;
00057 else
00058 QPixmapCache::insert( key, pix );
00059 return pix;
00060 } else kdWarning(1203) << "Couldn't locate wallpaper " << _wallpaper << endl;
00061 return QPixmap();
00062 }
00063
00064 struct KonqPropsView::Private
00065 {
00066 QStringList* previewsToShow;
00067 bool previewsEnabled:1;
00068 bool caseInsensitiveSort:1;
00069 };
00070
00071 KonqPropsView::KonqPropsView( KInstance * instance, KonqPropsView * defaultProps )
00072 : m_bSaveViewPropertiesLocally( false ),
00073
00074 m_dotDirExists( true ),
00075 m_currentConfig( defaultProps ? 0L : instance->config() ),
00076 m_defaultProps( defaultProps )
00077 {
00078
00079 KConfig *config = instance->config();
00080 KConfigGroupSaver cgs(config, "Settings");
00081
00082 d = new Private;
00083 d->previewsToShow = 0;
00084 d->caseInsensitiveSort=config->readBoolEntry( "CaseInsensitiveSort", false );
00085
00086 m_iIconSize = config->readNumEntry( "IconSize", 0 );
00087 m_iItemTextPos = config->readNumEntry( "ItemTextPos", QIconView::Bottom );
00088 m_bShowDot = config->readBoolEntry( "ShowDotFiles", false );
00089 m_bShowDirectoryOverlays = config->readBoolEntry( "ShowDirectoryOverlays", false );
00090
00091 m_dontPreview = config->readListEntry( "DontPreview" );
00092 m_dontPreview.remove("audio/");
00093
00094
00095
00096
00097 if (!config->readBoolEntry("EnableSoundPreviews", false))
00098 {
00099 if (!m_dontPreview.contains("audio/"))
00100 m_dontPreview.append("audio/");
00101 }
00102
00103 d->previewsEnabled = config->readBoolEntry( "PreviewsEnabled", true );
00104
00105 m_textColor = config->readColorEntry( "TextColor" );
00106 m_bgColor = config->readColorEntry( "BgColor" );
00107 m_bgPixmapFile = config->readPathEntry( "BgImage" );
00108
00109
00110
00111
00112
00113
00114 if (!defaultProps)
00115 {
00116 KConfigGroupSaver cgs2(KGlobal::config(), "Settings");
00117 m_textColor = KGlobal::config()->readColorEntry( "TextColor", &m_textColor );
00118 m_bgColor = KGlobal::config()->readColorEntry( "BgColor", &m_bgColor );
00119 m_bgPixmapFile = KGlobal::config()->readPathEntry( "BgImage", m_bgPixmapFile );
00120
00121 }
00122
00123 KGlobal::dirs()->addResourceType("tiles",
00124 KGlobal::dirs()->kde_default("data") + "konqueror/tiles/");
00125 }
00126
00127 bool KonqPropsView::isCaseInsensitiveSort() const
00128 {
00129 return d->caseInsensitiveSort;
00130 }
00131
00132
00133 KConfigBase * KonqPropsView::currentConfig()
00134 {
00135 if ( !m_currentConfig )
00136 {
00137
00138 assert ( m_bSaveViewPropertiesLocally );
00139 assert ( !isDefaultProperties() );
00140
00141 if (!dotDirectory.isEmpty())
00142 m_currentConfig = new KSimpleConfig( dotDirectory );
00143
00144 }
00145 return m_currentConfig;
00146 }
00147
00148 KConfigBase * KonqPropsView::currentColorConfig()
00149 {
00150
00151 if ( m_bSaveViewPropertiesLocally && !isDefaultProperties() )
00152 return currentConfig();
00153 else
00154
00155 return KGlobal::config();
00156 }
00157
00158 KonqPropsView::~KonqPropsView()
00159 {
00160 delete d->previewsToShow;
00161 delete d;
00162 d=0;
00163 }
00164
00165 bool KonqPropsView::enterDir( const KURL & dir )
00166 {
00167
00168
00169 assert( !isDefaultProperties() );
00170
00171
00172 KURL u ( dir );
00173 u.addPath(".directory");
00174 bool dotDirExists = u.isLocalFile() && QFile::exists( u.path() );
00175 dotDirectory = u.isLocalFile() ? u.path() : QString::null;
00176
00177
00178
00179 if (dotDirExists || m_dotDirExists)
00180 {
00181 m_iIconSize = m_defaultProps->iconSize();
00182 m_iItemTextPos = m_defaultProps->itemTextPos();
00183 m_bShowDot = m_defaultProps->isShowingDotFiles();
00184 d->caseInsensitiveSort=m_defaultProps->isCaseInsensitiveSort();
00185 m_dontPreview = m_defaultProps->m_dontPreview;
00186 m_textColor = m_defaultProps->m_textColor;
00187 m_bgColor = m_defaultProps->m_bgColor;
00188 m_bgPixmapFile = m_defaultProps->bgPixmapFile();
00189 }
00190
00191 if (dotDirExists)
00192 {
00193
00194 KSimpleConfig * config = new KSimpleConfig( dotDirectory, true );
00195 config->setGroup("URL properties");
00196
00197 m_iIconSize = config->readNumEntry( "IconSize", m_iIconSize );
00198 m_iItemTextPos = config->readNumEntry( "ItemTextPos", m_iItemTextPos );
00199 m_bShowDot = config->readBoolEntry( "ShowDotFiles", m_bShowDot );
00200 d->caseInsensitiveSort=config->readBoolEntry("CaseInsensitiveSort",d->caseInsensitiveSort);
00201 m_bShowDirectoryOverlays = config->readBoolEntry( "ShowDirectoryOverlays", m_bShowDirectoryOverlays );
00202 if (config->hasKey( "DontPreview" ))
00203 {
00204 m_dontPreview = config->readListEntry( "DontPreview" );
00205
00206
00207
00208
00209
00210 if (config->hasKey("EnableSoundPreviews"))
00211 {
00212
00213 if (!config->readBoolEntry("EnableSoundPreviews", false))
00214 if (!m_dontPreview.contains("audio/"))
00215 m_dontPreview.append("audio/");
00216 }
00217 else
00218 {
00219 if (m_defaultProps->m_dontPreview.contains("audio/"))
00220 if (!m_dontPreview.contains("audio/"))
00221 m_dontPreview.append("audio/");
00222 }
00223 }
00224
00225
00226
00227 m_textColor = config->readColorEntry( "TextColor", &m_textColor );
00228 m_bgColor = config->readColorEntry( "BgColor", &m_bgColor );
00229 m_bgPixmapFile = config->readPathEntry( "BgImage", m_bgPixmapFile );
00230
00231 d->previewsEnabled = config->readBoolEntry( "PreviewsEnabled", d->previewsEnabled );
00232 delete config;
00233 }
00234
00235 bool configChanged=(m_dotDirExists|| dotDirExists);
00236 m_dotDirExists = dotDirExists;
00237 m_currentConfig = 0L;
00238
00239 return configChanged;
00240 }
00241
00242 void KonqPropsView::setSaveViewPropertiesLocally( bool value )
00243 {
00244 assert( !isDefaultProperties() );
00245
00246
00247 if ( m_bSaveViewPropertiesLocally )
00248 delete m_currentConfig;
00249
00250 m_bSaveViewPropertiesLocally = value;
00251 m_currentConfig = 0L;
00252 }
00253
00254 void KonqPropsView::setIconSize( int size )
00255 {
00256 m_iIconSize = size;
00257 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
00258 m_defaultProps->setIconSize( size );
00259 else if (currentConfig())
00260 {
00261 KConfigGroupSaver cgs(currentConfig(), currentGroup());
00262 currentConfig()->writeEntry( "IconSize", m_iIconSize );
00263 currentConfig()->sync();
00264 }
00265 }
00266
00267 void KonqPropsView::setItemTextPos( int pos )
00268 {
00269 m_iItemTextPos = pos;
00270 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
00271 m_defaultProps->setItemTextPos( pos );
00272 else if (currentConfig())
00273 {
00274 KConfigGroupSaver cgs(currentConfig(), currentGroup());
00275 currentConfig()->writeEntry( "ItemTextPos", m_iItemTextPos );
00276 currentConfig()->sync();
00277 }
00278 }
00279
00280 void KonqPropsView::setShowingDotFiles( bool show )
00281 {
00282 kdDebug(1203) << "KonqPropsView::setShowingDotFiles " << show << endl;
00283 m_bShowDot = show;
00284 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
00285 {
00286 kdDebug(1203) << "Saving in default properties" << endl;
00287 m_defaultProps->setShowingDotFiles( show );
00288 }
00289 else if (currentConfig())
00290 {
00291 kdDebug(1203) << "Saving in current config" << endl;
00292 KConfigGroupSaver cgs(currentConfig(), currentGroup());
00293 currentConfig()->writeEntry( "ShowDotFiles", m_bShowDot );
00294 currentConfig()->sync();
00295 }
00296 }
00297
00298 void KonqPropsView::setCaseInsensitiveSort( bool on )
00299 {
00300 kdDebug(1203) << "KonqPropsView::setCaseInsensitiveSort " << on << endl;
00301 d->caseInsensitiveSort = on;
00302 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
00303 {
00304 kdDebug(1203) << "Saving in default properties" << endl;
00305 m_defaultProps->setCaseInsensitiveSort( on );
00306 }
00307 else if (currentConfig())
00308 {
00309 kdDebug(1203) << "Saving in current config" << endl;
00310 KConfigGroupSaver cgs(currentConfig(), currentGroup());
00311 currentConfig()->writeEntry( "CaseInsensitiveSort", d->caseInsensitiveSort );
00312 currentConfig()->sync();
00313 }
00314 }
00315
00316 void KonqPropsView::setShowingDirectoryOverlays( bool show )
00317 {
00318 kdDebug(1203) << "KonqPropsView::setShowingDirectoryOverlays " << show << endl;
00319 m_bShowDirectoryOverlays = show;
00320 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
00321 {
00322 kdDebug(1203) << "Saving in default properties" << endl;
00323 m_defaultProps->setShowingDirectoryOverlays( show );
00324 }
00325 else if (currentConfig())
00326 {
00327 kdDebug(1203) << "Saving in current config" << endl;
00328 KConfigGroupSaver cgs(currentConfig(), currentGroup());
00329 currentConfig()->writeEntry( "ShowDirectoryOverlays", m_bShowDirectoryOverlays );
00330 currentConfig()->sync();
00331 }
00332 }
00333
00334 void KonqPropsView::setShowingPreview( const QString &preview, bool show )
00335 {
00336 if ( m_dontPreview.contains( preview ) != show )
00337 return;
00338 else if ( show )
00339 m_dontPreview.remove( preview );
00340 else
00341 m_dontPreview.append( preview );
00342 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
00343 m_defaultProps->setShowingPreview( preview, show );
00344 else if (currentConfig())
00345 {
00346 KConfigGroupSaver cgs(currentConfig(), currentGroup());
00347
00348
00349
00350 bool audioEnabled = !m_dontPreview.contains("audio/");
00351
00352
00353 if (!audioEnabled)
00354 m_dontPreview.remove("audio/");
00355 currentConfig()->writeEntry( "DontPreview", m_dontPreview );
00356 currentConfig()->writeEntry( "EnableSoundPreviews", audioEnabled );
00357 currentConfig()->sync();
00358 if (!audioEnabled)
00359 m_dontPreview.append("audio/");
00360
00361 }
00362
00363 delete d->previewsToShow;
00364 d->previewsToShow = 0;
00365 }
00366
00367 void KonqPropsView::setShowingPreview( bool show )
00368 {
00369 d->previewsEnabled = show;
00370
00371 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
00372 {
00373 kdDebug(1203) << "Saving in default properties" << endl;
00374 m_defaultProps-> setShowingPreview( show );
00375 }
00376 else if (currentConfig())
00377 {
00378 kdDebug(1203) << "Saving in current config" << endl;
00379 KConfigGroupSaver cgs(currentConfig(), currentGroup());
00380 currentConfig()->writeEntry( "PreviewsEnabled", d->previewsEnabled );
00381 currentConfig()->sync();
00382 }
00383
00384 delete d->previewsToShow;
00385 d->previewsToShow = 0;
00386 }
00387
00388 bool KonqPropsView::isShowingPreview()
00389 {
00390 return d->previewsEnabled;
00391 }
00392
00393 void KonqPropsView::setBgColor( const QColor & color )
00394 {
00395 m_bgColor = color;
00396 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
00397 {
00398 m_defaultProps->setBgColor( color );
00399 }
00400 else
00401 {
00402 KConfigBase * colorConfig = currentColorConfig();
00403 if (colorConfig)
00404 {
00405 KConfigGroupSaver cgs(colorConfig, currentGroup());
00406 colorConfig->writeEntry( "BgColor", m_bgColor );
00407 colorConfig->sync();
00408 }
00409 }
00410 }
00411
00412 const QColor & KonqPropsView::bgColor( QWidget * widget ) const
00413 {
00414 if ( !m_bgColor.isValid() )
00415 return widget->colorGroup().base();
00416 else
00417 return m_bgColor;
00418 }
00419
00420 void KonqPropsView::setTextColor( const QColor & color )
00421 {
00422 m_textColor = color;
00423 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
00424 {
00425 m_defaultProps->setTextColor( color );
00426 }
00427 else
00428 {
00429 KConfigBase * colorConfig = currentColorConfig();
00430 if (colorConfig)
00431 {
00432 KConfigGroupSaver cgs(colorConfig, currentGroup());
00433 colorConfig->writeEntry( "TextColor", m_textColor );
00434 colorConfig->sync();
00435 }
00436 }
00437 }
00438
00439 const QColor & KonqPropsView::textColor( QWidget * widget ) const
00440 {
00441 if ( !m_textColor.isValid() )
00442 return widget->colorGroup().text();
00443 else
00444 return m_textColor;
00445 }
00446
00447 void KonqPropsView::setBgPixmapFile( const QString & file )
00448 {
00449 m_bgPixmapFile = file;
00450
00451 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
00452 {
00453 m_defaultProps->setBgPixmapFile( file );
00454 }
00455 else
00456 {
00457 KConfigBase * colorConfig = currentColorConfig();
00458 if (colorConfig)
00459 {
00460 KConfigGroupSaver cgs(colorConfig, currentGroup());
00461 colorConfig->writeEntry( "BgImage", file );
00462 colorConfig->sync();
00463 }
00464 }
00465 }
00466
00467 QPixmap KonqPropsView::loadPixmap() const
00468 {
00469
00470 QPixmap bgPixmap;
00471 if ( !m_bgPixmapFile.isEmpty() )
00472 bgPixmap = wallpaperPixmap( m_bgPixmapFile );
00473 return bgPixmap;
00474 }
00475
00476 void KonqPropsView::applyColors(QWidget * widget) const
00477 {
00478
00479 QColorGroup a = widget->palette().active();
00480 QColorGroup d = widget->palette().disabled();
00481 QColorGroup i = widget->palette().inactive();
00482 bool setPaletteNeeded = false;
00483
00484 if ( m_bgPixmapFile.isEmpty() )
00485 {
00486 QColor col = bgColor(widget);
00487 a.setColor( QColorGroup::Base, col );
00488 d.setColor( QColorGroup::Base, col );
00489 i.setColor( QColorGroup::Base, col );
00490 widget->setBackgroundColor( col );
00491 setPaletteNeeded = true;
00492 }
00493 else
00494 {
00495 widget->setPaletteBackgroundPixmap( loadPixmap() );
00496 }
00497
00498 if ( m_textColor.isValid() )
00499 {
00500 a.setColor( QColorGroup::Text, m_textColor );
00501 d.setColor( QColorGroup::Text, m_textColor );
00502 i.setColor( QColorGroup::Text, m_textColor );
00503 setPaletteNeeded = true;
00504 }
00505
00506
00507
00508 if ( setPaletteNeeded )
00509 widget->setPalette( QPalette( a, d, i ) );
00510 }
00511
00512 const QStringList& KonqPropsView::previewSettings()
00513 {
00514 if ( ! d->previewsToShow )
00515 {
00516 d->previewsToShow = new QStringList;
00517
00518 if (d->previewsEnabled) {
00519 KTrader::OfferList plugins = KTrader::self()->query( "ThumbCreator" );
00520 for ( KTrader::OfferList::ConstIterator it = plugins.begin(); it != plugins.end(); ++it )
00521 {
00522 QString name = (*it)->desktopEntryName();
00523 if ( ! m_dontPreview.contains(name) )
00524 d->previewsToShow->append( name );
00525 }
00526 if ( ! m_dontPreview.contains( "audio/" ) )
00527 d->previewsToShow->append( "audio/" );
00528 }
00529 }
00530
00531 return *(d->previewsToShow);
00532 }