libkonq Library API Documentation

konq_propsview.cc

00001 /* This file is part of the KDE project 00002 Copyright (C) 1998, 1999 Faure David <faure@kde.org> 00003 00004 This program is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU 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 program 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 General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; see the file COPYING. If not, write to 00016 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 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 <qpixmapcache.h> 00027 #include <qiconview.h> 00028 #include <unistd.h> 00029 #include <qfile.h> 00030 #include <iostream> 00031 #include <ktrader.h> 00032 #include <kinstance.h> 00033 #include <assert.h> 00034 00035 #include <ksimpleconfig.h> 00036 00037 static QPixmap wallpaperPixmap( const QString & _wallpaper ) 00038 { 00039 QString key = "wallpapers/"; 00040 key += _wallpaper; 00041 KPixmap pix; 00042 00043 if ( QPixmapCache::find( key, pix ) ) 00044 return pix; 00045 00046 QString path = locate("tiles", _wallpaper); 00047 if (path.isEmpty()) 00048 path = locate("wallpaper", _wallpaper); 00049 if (!path.isEmpty()) 00050 { 00051 // This looks really ugly, especially on an 8bit display. 00052 // I'm not sure what it's good for. 00053 // Anyway, if you change it here, keep konq_bgnddlg in sync (David) 00054 // pix.load( path, 0, KPixmap::LowColor ); 00055 pix.load( path ); 00056 if ( pix.isNull() ) 00057 kdWarning(1203) << "Could not load wallpaper " << path << endl; 00058 else 00059 QPixmapCache::insert( key, pix ); 00060 return pix; 00061 } else kdWarning(1203) << "Couldn't locate wallpaper " << _wallpaper << endl; 00062 return QPixmap(); 00063 } 00064 00065 struct KonqPropsView::Private 00066 { 00067 QStringList* previewsToShow; 00068 bool previewsEnabled:1; 00069 bool caseInsensitiveSort:1; 00070 bool dirsfirst:1; 00071 bool descending:1; 00072 QString sortcriterion; 00073 }; 00074 00075 KonqPropsView::KonqPropsView( KInstance * instance, KonqPropsView * defaultProps ) 00076 : m_bSaveViewPropertiesLocally( false ), // will be overridden by setSave... anyway 00077 // if this is the default properties instance, then keep config object for saving 00078 m_dotDirExists( true ), // HACK so that enterDir returns true initially 00079 m_currentConfig( defaultProps ? 0L : instance->config() ), 00080 m_defaultProps( defaultProps ) 00081 { 00082 00083 KConfig *config = instance->config(); 00084 KConfigGroupSaver 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", QIconView::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 00098 m_dontPreview = config->readListEntry( "DontPreview" ); 00099 m_dontPreview.remove("audio/"); //Use the separate setting. 00100 //We default to this off anyway, so it's no harm to remove this 00101 00102 //The setting for sound previews is stored separately, so we can force 00103 //the default-to-off bias to propagate up. 00104 if (!config->readBoolEntry("EnableSoundPreviews", false)) 00105 { 00106 if (!m_dontPreview.contains("audio/")) 00107 m_dontPreview.append("audio/"); 00108 } 00109 00110 d->previewsEnabled = config->readBoolEntry( "PreviewsEnabled", true ); 00111 00112 QColor tc = KonqFMSettings::settings()->normalTextColor(); 00113 m_textColor = config->readColorEntry( "TextColor", &tc ); 00114 m_bgColor = config->readColorEntry( "BgColor" ); // will be set to QColor() if not found 00115 m_bgPixmapFile = config->readPathEntry( "BgImage" ); 00116 //kdDebug(1203) << "KonqPropsView::KonqPropsView from \"config\" : BgImage=" << m_bgPixmapFile << endl; 00117 00118 // colorsConfig is either the local file (.directory) or the application global file 00119 // (we want the same colors for all types of view) 00120 // The code above reads from the view's config file, for compatibility only. 00121 // So now we read the settings from the app global file, if this is the default props 00122 if (!defaultProps) 00123 { 00124 KConfigGroupSaver cgs2(KGlobal::config(), "Settings"); 00125 m_textColor = KGlobal::config()->readColorEntry( "TextColor", &m_textColor ); 00126 m_bgColor = KGlobal::config()->readColorEntry( "BgColor", &m_bgColor ); 00127 m_bgPixmapFile = KGlobal::config()->readPathEntry( "BgImage", m_bgPixmapFile ); 00128 //kdDebug(1203) << "KonqPropsView::KonqPropsView from KGlobal : BgImage=" << m_bgPixmapFile << endl; 00129 } 00130 00131 KGlobal::dirs()->addResourceType("tiles", 00132 KGlobal::dirs()->kde_default("data") + "konqueror/tiles/"); 00133 } 00134 00135 bool KonqPropsView::isCaseInsensitiveSort() const 00136 { 00137 return d->caseInsensitiveSort; 00138 } 00139 00140 bool KonqPropsView::isDirsFirst() const 00141 { 00142 return d->dirsfirst; 00143 } 00144 00145 bool KonqPropsView::isDescending() const 00146 { 00147 return d->descending; 00148 } 00149 00150 KConfigBase * KonqPropsView::currentConfig() 00151 { 00152 if ( !m_currentConfig ) 00153 { 00154 // 0L ? This has to be a non-default save-locally instance... 00155 assert ( m_bSaveViewPropertiesLocally ); 00156 assert ( !isDefaultProperties() ); 00157 00158 if (!dotDirectory.isEmpty()) 00159 m_currentConfig = new KSimpleConfig( dotDirectory ); 00160 // the "else" is when we want to save locally but this is a remote URL -> no save 00161 } 00162 return m_currentConfig; 00163 } 00164 00165 KConfigBase * KonqPropsView::currentColorConfig() 00166 { 00167 // Saving locally ? 00168 if ( m_bSaveViewPropertiesLocally && !isDefaultProperties() ) 00169 return currentConfig(); // Will create it if necessary 00170 else 00171 // Save color settings in app's file, not in view's file 00172 return KGlobal::config(); 00173 } 00174 00175 KonqPropsView::~KonqPropsView() 00176 { 00177 delete d->previewsToShow; 00178 delete d; 00179 d=0; 00180 } 00181 00182 bool KonqPropsView::enterDir( const KURL & dir ) 00183 { 00184 //kdDebug(1203) << "enterDir " << dir.prettyURL() << endl; 00185 // Can't do that with default properties 00186 assert( !isDefaultProperties() ); 00187 00188 // Check for .directory 00189 KURL u ( dir ); 00190 u.addPath(".directory"); 00191 bool dotDirExists = u.isLocalFile() && QFile::exists( u.path() ); 00192 dotDirectory = u.isLocalFile() ? u.path() : QString::null; 00193 00194 // Revert to default setting first - unless there is no .directory 00195 // in the previous dir nor in this one (then we can keep the current settings) 00196 if (dotDirExists || m_dotDirExists) 00197 { 00198 m_iIconSize = m_defaultProps->iconSize(); 00199 m_iItemTextPos = m_defaultProps->itemTextPos(); 00200 d->sortcriterion = m_defaultProps->sortCriterion(); 00201 d->dirsfirst = m_defaultProps->isDirsFirst(); 00202 d->descending = m_defaultProps->isDescending(); 00203 m_bShowDot = m_defaultProps->isShowingDotFiles(); 00204 d->caseInsensitiveSort=m_defaultProps->isCaseInsensitiveSort(); 00205 m_dontPreview = m_defaultProps->m_dontPreview; 00206 m_textColor = m_defaultProps->m_textColor; 00207 m_bgColor = m_defaultProps->m_bgColor; 00208 m_bgPixmapFile = m_defaultProps->bgPixmapFile(); 00209 } 00210 00211 if (dotDirExists) 00212 { 00213 //kdDebug(1203) << "Found .directory file" << endl; 00214 KSimpleConfig * config = new KSimpleConfig( dotDirectory, true ); 00215 config->setGroup("URL properties"); 00216 00217 m_iIconSize = config->readNumEntry( "IconSize", m_iIconSize ); 00218 m_iItemTextPos = config->readNumEntry( "ItemTextPos", m_iItemTextPos ); 00219 d->sortcriterion = config->readEntry( "SortingCriterion" , d->sortcriterion ); 00220 d->dirsfirst = config->readBoolEntry( "SortDirsFirst", d->dirsfirst ); 00221 d->descending = config->readBoolEntry( "SortDescending", d->descending ); 00222 m_bShowDot = config->readBoolEntry( "ShowDotFiles", m_bShowDot ); 00223 d->caseInsensitiveSort=config->readBoolEntry("CaseInsensitiveSort",d->caseInsensitiveSort); 00224 m_bShowDirectoryOverlays = config->readBoolEntry( "ShowDirectoryOverlays", m_bShowDirectoryOverlays ); 00225 if (config->hasKey( "DontPreview" )) 00226 { 00227 m_dontPreview = config->readListEntry( "DontPreview" ); 00228 00229 //If the .directory file says something about sound previews, 00230 //obey it, otherwise propagate the setting up from the defaults 00231 //All this really should be split into a per-thumbnail setting, 00232 //but that's too invasive at this point 00233 if (config->hasKey("EnableSoundPreviews")) 00234 { 00235 00236 if (!config->readBoolEntry("EnableSoundPreviews", false)) 00237 if (!m_dontPreview.contains("audio/")) 00238 m_dontPreview.append("audio/"); 00239 } 00240 else 00241 { 00242 if (m_defaultProps->m_dontPreview.contains("audio/")) 00243 if (!m_dontPreview.contains("audio/")) 00244 m_dontPreview.append("audio/"); 00245 } 00246 } 00247 00248 00249 00250 m_textColor = config->readColorEntry( "TextColor", &m_textColor ); 00251 m_bgColor = config->readColorEntry( "BgColor", &m_bgColor ); 00252 m_bgPixmapFile = config->readPathEntry( "BgImage", m_bgPixmapFile ); 00253 //kdDebug(1203) << "KonqPropsView::enterDir m_bgPixmapFile=" << m_bgPixmapFile << endl; 00254 d->previewsEnabled = config->readBoolEntry( "PreviewsEnabled", d->previewsEnabled ); 00255 delete config; 00256 } 00257 //if there is or was a .directory then the settings probably have changed 00258 bool configChanged=(m_dotDirExists|| dotDirExists); 00259 m_dotDirExists = dotDirExists; 00260 m_currentConfig = 0L; // new dir, not current config for saving yet 00261 //kdDebug(1203) << "KonqPropsView::enterDir returning " << configChanged << endl; 00262 return configChanged; 00263 } 00264 00265 void KonqPropsView::setSaveViewPropertiesLocally( bool value ) 00266 { 00267 assert( !isDefaultProperties() ); 00268 //kdDebug(1203) << "KonqPropsView::setSaveViewPropertiesLocally " << value << endl; 00269 00270 if ( m_bSaveViewPropertiesLocally ) 00271 delete m_currentConfig; // points to a KSimpleConfig 00272 00273 m_bSaveViewPropertiesLocally = value; 00274 m_currentConfig = 0L; // mark as dirty 00275 } 00276 00277 void KonqPropsView::setIconSize( int size ) 00278 { 00279 m_iIconSize = size; 00280 if ( m_defaultProps && !m_bSaveViewPropertiesLocally ) 00281 m_defaultProps->setIconSize( size ); 00282 else if (currentConfig()) 00283 { 00284 KConfigGroupSaver cgs(currentConfig(), currentGroup()); 00285 currentConfig()->writeEntry( "IconSize", m_iIconSize ); 00286 currentConfig()->sync(); 00287 } 00288 } 00289 00290 void KonqPropsView::setItemTextPos( int pos ) 00291 { 00292 m_iItemTextPos = pos; 00293 if ( m_defaultProps && !m_bSaveViewPropertiesLocally ) 00294 m_defaultProps->setItemTextPos( pos ); 00295 else if (currentConfig()) 00296 { 00297 KConfigGroupSaver cgs(currentConfig(), currentGroup()); 00298 currentConfig()->writeEntry( "ItemTextPos", m_iItemTextPos ); 00299 currentConfig()->sync(); 00300 } 00301 } 00302 00303 void KonqPropsView::setSortCriterion( const QString &criterion ) 00304 { 00305 d->sortcriterion = criterion; 00306 if ( m_defaultProps && !m_bSaveViewPropertiesLocally ) 00307 m_defaultProps->setSortCriterion( criterion ); 00308 else if (currentConfig()) 00309 { 00310 KConfigGroupSaver cgs(currentConfig(), currentGroup()); 00311 currentConfig()->writeEntry( "SortingCriterion", d->sortcriterion ); 00312 currentConfig()->sync(); 00313 } 00314 } 00315 00316 void KonqPropsView::setDirsFirst( bool first) 00317 { 00318 d->dirsfirst = first; 00319 if ( m_defaultProps && !m_bSaveViewPropertiesLocally ) 00320 m_defaultProps->setDirsFirst( first ); 00321 else if (currentConfig()) 00322 { 00323 KConfigGroupSaver cgs(currentConfig(), currentGroup()); 00324 currentConfig()->writeEntry( "SortDirsFirst", d->dirsfirst ); 00325 currentConfig()->sync(); 00326 } 00327 } 00328 00329 void KonqPropsView::setDescending( bool descend) 00330 { 00331 d->descending = descend; 00332 if ( m_defaultProps && !m_bSaveViewPropertiesLocally ) 00333 m_defaultProps->setDescending( descend ); 00334 else if (currentConfig()) 00335 { 00336 KConfigGroupSaver cgs(currentConfig(), currentGroup()); 00337 currentConfig()->writeEntry( "SortDescending", d->descending ); 00338 currentConfig()->sync(); 00339 } 00340 } 00341 00342 void KonqPropsView::setShowingDotFiles( bool show ) 00343 { 00344 kdDebug(1203) << "KonqPropsView::setShowingDotFiles " << show << endl; 00345 m_bShowDot = show; 00346 if ( m_defaultProps && !m_bSaveViewPropertiesLocally ) 00347 { 00348 kdDebug(1203) << "Saving in default properties" << endl; 00349 m_defaultProps->setShowingDotFiles( show ); 00350 } 00351 else if (currentConfig()) 00352 { 00353 kdDebug(1203) << "Saving in current config" << endl; 00354 KConfigGroupSaver cgs(currentConfig(), currentGroup()); 00355 currentConfig()->writeEntry( "ShowDotFiles", m_bShowDot ); 00356 currentConfig()->sync(); 00357 } 00358 } 00359 00360 void KonqPropsView::setCaseInsensitiveSort( bool on ) 00361 { 00362 kdDebug(1203) << "KonqPropsView::setCaseInsensitiveSort " << on << endl; 00363 d->caseInsensitiveSort = on; 00364 if ( m_defaultProps && !m_bSaveViewPropertiesLocally ) 00365 { 00366 kdDebug(1203) << "Saving in default properties" << endl; 00367 m_defaultProps->setCaseInsensitiveSort( on ); 00368 } 00369 else if (currentConfig()) 00370 { 00371 kdDebug(1203) << "Saving in current config" << endl; 00372 KConfigGroupSaver cgs(currentConfig(), currentGroup()); 00373 currentConfig()->writeEntry( "CaseInsensitiveSort", d->caseInsensitiveSort ); 00374 currentConfig()->sync(); 00375 } 00376 } 00377 00378 void KonqPropsView::setShowingDirectoryOverlays( bool show ) 00379 { 00380 kdDebug(1203) << "KonqPropsView::setShowingDirectoryOverlays " << show << endl; 00381 m_bShowDirectoryOverlays = show; 00382 if ( m_defaultProps && !m_bSaveViewPropertiesLocally ) 00383 { 00384 kdDebug(1203) << "Saving in default properties" << endl; 00385 m_defaultProps->setShowingDirectoryOverlays( show ); 00386 } 00387 else if (currentConfig()) 00388 { 00389 kdDebug(1203) << "Saving in current config" << endl; 00390 KConfigGroupSaver cgs(currentConfig(), currentGroup()); 00391 currentConfig()->writeEntry( "ShowDirectoryOverlays", m_bShowDirectoryOverlays ); 00392 currentConfig()->sync(); 00393 } 00394 } 00395 00396 void KonqPropsView::setShowingPreview( const QString &preview, bool show ) 00397 { 00398 if ( m_dontPreview.contains( preview ) != show ) 00399 return; 00400 else if ( show ) 00401 m_dontPreview.remove( preview ); 00402 else 00403 m_dontPreview.append( preview ); 00404 if ( m_defaultProps && !m_bSaveViewPropertiesLocally ) 00405 m_defaultProps->setShowingPreview( preview, show ); 00406 else if (currentConfig()) 00407 { 00408 KConfigGroupSaver cgs(currentConfig(), currentGroup()); 00409 00410 //Audio is special-cased, as we use a binary setting 00411 //for it to get it to follow the defaults right. 00412 bool audioEnabled = !m_dontPreview.contains("audio/"); 00413 00414 //Don't write it out into the DontPreview line 00415 if (!audioEnabled) 00416 m_dontPreview.remove("audio/"); 00417 currentConfig()->writeEntry( "DontPreview", m_dontPreview ); 00418 currentConfig()->writeEntry( "EnableSoundPreviews", audioEnabled ); 00419 currentConfig()->sync(); 00420 if (!audioEnabled) 00421 m_dontPreview.append("audio/"); 00422 00423 } 00424 00425 delete d->previewsToShow; 00426 d->previewsToShow = 0; 00427 } 00428 00429 void KonqPropsView::setShowingPreview( bool show ) 00430 { 00431 d->previewsEnabled = show; 00432 00433 if ( m_defaultProps && !m_bSaveViewPropertiesLocally ) 00434 { 00435 kdDebug(1203) << "Saving in default properties" << endl; 00436 m_defaultProps-> setShowingPreview( show ); 00437 } 00438 else if (currentConfig()) 00439 { 00440 kdDebug(1203) << "Saving in current config" << endl; 00441 KConfigGroupSaver cgs(currentConfig(), currentGroup()); 00442 currentConfig()->writeEntry( "PreviewsEnabled", d->previewsEnabled ); 00443 currentConfig()->sync(); 00444 } 00445 00446 delete d->previewsToShow; 00447 d->previewsToShow = 0; 00448 } 00449 00450 bool KonqPropsView::isShowingPreview() 00451 { 00452 return d->previewsEnabled; 00453 } 00454 00455 void KonqPropsView::setBgColor( const QColor & color ) 00456 { 00457 m_bgColor = color; 00458 if ( m_defaultProps && !m_bSaveViewPropertiesLocally ) 00459 { 00460 m_defaultProps->setBgColor( color ); 00461 } 00462 else 00463 { 00464 KConfigBase * colorConfig = currentColorConfig(); 00465 if (colorConfig) // 0L when saving locally but remote URL 00466 { 00467 KConfigGroupSaver cgs(colorConfig, currentGroup()); 00468 colorConfig->writeEntry( "BgColor", m_bgColor ); 00469 colorConfig->sync(); 00470 } 00471 } 00472 } 00473 00474 const QColor & KonqPropsView::bgColor( QWidget * widget ) const 00475 { 00476 if ( !m_bgColor.isValid() ) 00477 return widget->colorGroup().base(); 00478 else 00479 return m_bgColor; 00480 } 00481 00482 void KonqPropsView::setTextColor( const QColor & color ) 00483 { 00484 m_textColor = color; 00485 if ( m_defaultProps && !m_bSaveViewPropertiesLocally ) 00486 { 00487 m_defaultProps->setTextColor( color ); 00488 } 00489 else 00490 { 00491 KConfigBase * colorConfig = currentColorConfig(); 00492 if (colorConfig) // 0L when saving locally but remote URL 00493 { 00494 KConfigGroupSaver cgs(colorConfig, currentGroup()); 00495 colorConfig->writeEntry( "TextColor", m_textColor ); 00496 colorConfig->sync(); 00497 } 00498 } 00499 } 00500 00501 const QColor & KonqPropsView::textColor( QWidget * widget ) const 00502 { 00503 if ( !m_textColor.isValid() ) 00504 return widget->colorGroup().text(); 00505 else 00506 return m_textColor; 00507 } 00508 00509 void KonqPropsView::setBgPixmapFile( const QString & file ) 00510 { 00511 m_bgPixmapFile = file; 00512 00513 if ( m_defaultProps && !m_bSaveViewPropertiesLocally ) 00514 { 00515 m_defaultProps->setBgPixmapFile( file ); 00516 } 00517 else 00518 { 00519 KConfigBase * colorConfig = currentColorConfig(); 00520 if (colorConfig) // 0L when saving locally but remote URL 00521 { 00522 KConfigGroupSaver cgs(colorConfig, currentGroup()); 00523 colorConfig->writePathEntry( "BgImage", file ); 00524 colorConfig->sync(); 00525 } 00526 } 00527 } 00528 00529 QPixmap KonqPropsView::loadPixmap() const 00530 { 00531 //kdDebug(1203) << "KonqPropsView::loadPixmap " << m_bgPixmapFile << endl; 00532 QPixmap bgPixmap; 00533 if ( !m_bgPixmapFile.isEmpty() ) 00534 bgPixmap = wallpaperPixmap( m_bgPixmapFile ); 00535 return bgPixmap; 00536 } 00537 00538 void KonqPropsView::applyColors(QWidget * widget) const 00539 { 00540 if ( m_bgPixmapFile.isEmpty() ) 00541 widget->setPaletteBackgroundColor( bgColor( widget ) ); 00542 else 00543 widget->setPaletteBackgroundPixmap( loadPixmap() ); 00544 00545 if ( m_textColor.isValid() ) 00546 widget->setPaletteForegroundColor( m_textColor ); 00547 } 00548 00549 const QStringList& KonqPropsView::previewSettings() 00550 { 00551 if ( ! d->previewsToShow ) 00552 { 00553 d->previewsToShow = new QStringList; 00554 00555 if (d->previewsEnabled) { 00556 KTrader::OfferList plugins = KTrader::self()->query( "ThumbCreator" ); 00557 for ( KTrader::OfferList::ConstIterator it = plugins.begin(); it != plugins.end(); ++it ) 00558 { 00559 QString name = (*it)->desktopEntryName(); 00560 if ( ! m_dontPreview.contains(name) ) 00561 d->previewsToShow->append( name ); 00562 } 00563 if ( ! m_dontPreview.contains( "audio/" ) ) 00564 d->previewsToShow->append( "audio/" ); 00565 } 00566 } 00567 00568 return *(d->previewsToShow); 00569 } 00570 00571 const QString& KonqPropsView::sortCriterion() const { 00572 return d->sortcriterion; 00573 } 00574
KDE Logo
This file is part of the documentation for libkonq Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Sep 16 15:59:26 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003