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