20 #include "konq_propsview.h"
21 #include "konq_settings.h"
24 #include <kstandarddirs.h>
26 #include <tqpixmapcache.h>
27 #include <tqiconview.h>
32 #include <kinstance.h>
35 #include <ksimpleconfig.h>
37 #include "konq_sort_constants.h"
39 static TQPixmap wallpaperPixmap(
const TQString & _wallpaper )
41 TQString key =
"wallpapers/";
45 if ( TQPixmapCache::find( key, pix ) )
48 TQString path = locate(
"tiles", _wallpaper);
50 path = locate(
"wallpaper", _wallpaper);
59 kdWarning(1203) <<
"Could not load wallpaper " << path << endl;
61 TQPixmapCache::insert( key, pix );
63 }
else kdWarning(1203) <<
"Couldn't locate wallpaper " << _wallpaper << endl;
67 struct KonqPropsView::Private
69 TQStringList* previewsToShow;
70 TextSortOrder textSortOrder;
71 bool previewsEnabled:1;
72 bool caseInsensitiveSort:1;
76 TQString sortcriterion;
80 : m_bSaveViewPropertiesLocally( false ),
82 m_dotDirExists( true ),
83 m_currentConfig( defaultProps ? 0L : instance->config() ),
84 m_defaultProps( defaultProps )
87 TDEConfig *config = instance->config();
88 TDEConfigGroupSaver cgs(config,
"Settings");
91 d->previewsToShow = 0;
92 d->caseInsensitiveSort=config->readBoolEntry(
"CaseInsensitiveSort",
true );
94 m_iIconSize = config->readNumEntry(
"IconSize", 0 );
95 m_iItemTextPos = config->readNumEntry(
"ItemTextPos", TQIconView::Bottom );
96 d->sortcriterion = config->readEntry(
"SortingCriterion",
"sort_nci" );
97 d->textSortOrder = (TextSortOrder) config->readNumEntry(
"TextSortOrder", 1 );
98 d->dirsfirst = config->readBoolEntry(
"SortDirsFirst",
true );
99 d->hiddenfirst = config->readBoolEntry(
"SortHiddenFirst",
true );
100 d->descending = config->readBoolEntry(
"SortDescending",
false );
101 m_bShowDot = config->readBoolEntry(
"ShowDotFiles",
false );
102 m_bShowDirectoryOverlays = config->readBoolEntry(
"ShowDirectoryOverlays",
false );
103 m_bShowFreeSpaceOverlays = config->readBoolEntry(
"ShowFreeSpaceOverlays",
true );
105 m_dontPreview = config->readListEntry(
"DontPreview" );
106 m_dontPreview.remove(
"audio/");
111 if (!config->readBoolEntry(
"EnableSoundPreviews",
false))
113 if (!m_dontPreview.contains(
"audio/"))
114 m_dontPreview.append(
"audio/");
117 d->previewsEnabled = config->readBoolEntry(
"PreviewsEnabled",
true );
120 m_textColor = config->readColorEntry(
"TextColor", &tc );
121 m_bgColor = config->readColorEntry(
"BgColor" );
122 m_bgPixmapFile = config->readPathEntry(
"BgImage" );
131 TDEConfigGroupSaver cgs2(TDEGlobal::config(),
"Settings");
132 m_textColor = TDEGlobal::config()->readColorEntry(
"TextColor", &m_textColor );
133 m_bgColor = TDEGlobal::config()->readColorEntry(
"BgColor", &m_bgColor );
134 m_bgPixmapFile = TDEGlobal::config()->readPathEntry(
"BgImage", m_bgPixmapFile );
138 TDEGlobal::dirs()->addResourceType(
"tiles",
139 TDEGlobal::dirs()->kde_default(
"data") +
"konqueror/tiles/");
142 bool KonqPropsView::isCaseInsensitiveSort()
const
144 return d->caseInsensitiveSort;
147 TextSortOrder KonqPropsView::getSortOrder()
const
149 return d->textSortOrder;
152 bool KonqPropsView::isDirsFirst()
const
157 bool KonqPropsView::isHiddenFirst()
const
159 return d->hiddenfirst;
162 bool KonqPropsView::isDescending()
const
164 return d->descending;
167 TDEConfigBase * KonqPropsView::currentConfig()
169 if ( !m_currentConfig )
172 assert ( m_bSaveViewPropertiesLocally );
175 if (!dotDirectory.isEmpty())
176 m_currentConfig =
new KSimpleConfig( dotDirectory );
179 return m_currentConfig;
182 TDEConfigBase * KonqPropsView::currentColorConfig()
186 return currentConfig();
189 return TDEGlobal::config();
194 delete d->previewsToShow;
207 u.addPath(
".directory");
208 bool dotDirExists = u.isLocalFile() && TQFile::exists( u.path() );
209 dotDirectory = u.isLocalFile() ? u.path() : TQString::null;
213 if (dotDirExists || m_dotDirExists)
215 m_iIconSize = m_defaultProps->iconSize();
216 m_iItemTextPos = m_defaultProps->itemTextPos();
217 d->sortcriterion = m_defaultProps->sortCriterion();
218 d->textSortOrder = m_defaultProps->getSortOrder();
219 d->dirsfirst = m_defaultProps->isDirsFirst();
220 d->hiddenfirst = m_defaultProps->isHiddenFirst();
221 d->descending = m_defaultProps->isDescending();
222 m_bShowDot = m_defaultProps->isShowingDotFiles();
223 d->caseInsensitiveSort=m_defaultProps->isCaseInsensitiveSort();
224 m_dontPreview = m_defaultProps->m_dontPreview;
225 m_textColor = m_defaultProps->m_textColor;
226 m_bgColor = m_defaultProps->m_bgColor;
227 m_bgPixmapFile = m_defaultProps->bgPixmapFile();
233 KSimpleConfig * config =
new KSimpleConfig( dotDirectory,
true );
234 config->setGroup(
"URL properties");
236 m_iIconSize = config->readNumEntry(
"IconSize", m_iIconSize );
237 m_iItemTextPos = config->readNumEntry(
"ItemTextPos", m_iItemTextPos );
238 d->sortcriterion = config->readEntry(
"SortingCriterion" , d->sortcriterion );
239 d->textSortOrder = (TextSortOrder) config->readNumEntry(
"TextSortOrder", d->textSortOrder );
240 d->dirsfirst = config->readBoolEntry(
"SortDirsFirst", d->dirsfirst );
241 d->hiddenfirst = config->readBoolEntry(
"SortHiddenFirst", d->hiddenfirst );
242 d->descending = config->readBoolEntry(
"SortDescending", d->descending );
243 m_bShowDot = config->readBoolEntry(
"ShowDotFiles", m_bShowDot );
244 d->caseInsensitiveSort=config->readBoolEntry(
"CaseInsensitiveSort",d->caseInsensitiveSort);
245 m_bShowDirectoryOverlays = config->readBoolEntry(
"ShowDirectoryOverlays", m_bShowDirectoryOverlays );
246 m_bShowFreeSpaceOverlays = config->readBoolEntry(
"ShowFreeSpaceOverlays", m_bShowFreeSpaceOverlays );
247 if (config->hasKey(
"DontPreview" ))
249 m_dontPreview = config->readListEntry(
"DontPreview" );
255 if (config->hasKey(
"EnableSoundPreviews"))
258 if (!config->readBoolEntry(
"EnableSoundPreviews",
false))
259 if (!m_dontPreview.contains(
"audio/"))
260 m_dontPreview.append(
"audio/");
264 if (m_defaultProps->m_dontPreview.contains(
"audio/"))
265 if (!m_dontPreview.contains(
"audio/"))
266 m_dontPreview.append(
"audio/");
272 m_textColor = config->readColorEntry(
"TextColor", &m_textColor );
273 m_bgColor = config->readColorEntry(
"BgColor", &m_bgColor );
274 m_bgPixmapFile = config->readPathEntry(
"BgImage", m_bgPixmapFile );
276 d->previewsEnabled = config->readBoolEntry(
"PreviewsEnabled", d->previewsEnabled );
280 bool configChanged=(m_dotDirExists|| dotDirExists);
281 m_dotDirExists = dotDirExists;
282 m_currentConfig = 0L;
284 return configChanged;
292 if ( m_bSaveViewPropertiesLocally )
293 delete m_currentConfig;
295 m_bSaveViewPropertiesLocally = value;
296 m_currentConfig = 0L;
299 void KonqPropsView::setIconSize(
int size )
302 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
303 m_defaultProps->setIconSize( size );
304 else if (currentConfig())
306 TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
307 currentConfig()->writeEntry(
"IconSize", m_iIconSize );
308 currentConfig()->sync();
312 void KonqPropsView::setItemTextPos(
int pos )
314 m_iItemTextPos = pos;
315 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
316 m_defaultProps->setItemTextPos( pos );
317 else if (currentConfig())
319 TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
320 currentConfig()->writeEntry(
"ItemTextPos", m_iItemTextPos );
321 currentConfig()->sync();
325 void KonqPropsView::setSortCriterion(
const TQString &criterion )
327 d->sortcriterion = criterion;
328 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
329 m_defaultProps->setSortCriterion( criterion );
330 else if (currentConfig())
332 TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
333 currentConfig()->writeEntry(
"SortingCriterion", d->sortcriterion );
334 currentConfig()->sync();
338 void KonqPropsView::setSortOrder( TextSortOrder order)
340 d->textSortOrder = order;
341 if ( m_defaultProps && !m_bSaveViewPropertiesLocally ) {
342 m_defaultProps->setSortOrder( order );
344 else if (currentConfig())
346 TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
347 currentConfig()->writeEntry(
"TextSortOrder", d->textSortOrder );
348 currentConfig()->sync();
352 void KonqPropsView::setDirsFirst(
bool first)
354 d->dirsfirst = first;
355 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
356 m_defaultProps->setDirsFirst( first );
357 else if (currentConfig())
359 TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
360 currentConfig()->writeEntry(
"SortDirsFirst", d->dirsfirst );
361 currentConfig()->sync();
365 void KonqPropsView::setHiddenFirst(
bool first)
367 d->hiddenfirst = first;
368 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
369 m_defaultProps->setHiddenFirst( first );
370 else if (currentConfig())
372 TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
373 currentConfig()->writeEntry(
"SortHiddenFirst", d->hiddenfirst );
374 currentConfig()->sync();
378 void KonqPropsView::setDescending(
bool descend)
380 d->descending = descend;
381 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
382 m_defaultProps->setDescending( descend );
383 else if (currentConfig())
385 TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
386 currentConfig()->writeEntry(
"SortDescending", d->descending );
387 currentConfig()->sync();
391 void KonqPropsView::setShowingDotFiles(
bool show )
393 kdDebug(1203) <<
"KonqPropsView::setShowingDotFiles " << show << endl;
395 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
397 kdDebug(1203) <<
"Saving in default properties" << endl;
398 m_defaultProps->setShowingDotFiles( show );
400 else if (currentConfig())
402 kdDebug(1203) <<
"Saving in current config" << endl;
403 TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
404 currentConfig()->writeEntry(
"ShowDotFiles", m_bShowDot );
405 currentConfig()->sync();
409 void KonqPropsView::setCaseInsensitiveSort(
bool on )
411 kdDebug(1203) <<
"KonqPropsView::setCaseInsensitiveSort " << on << endl;
412 d->caseInsensitiveSort = on;
413 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
415 kdDebug(1203) <<
"Saving in default properties" << endl;
416 m_defaultProps->setCaseInsensitiveSort( on );
418 else if (currentConfig())
420 kdDebug(1203) <<
"Saving in current config" << endl;
421 TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
422 currentConfig()->writeEntry(
"CaseInsensitiveSort", d->caseInsensitiveSort );
423 currentConfig()->sync();
427 void KonqPropsView::setShowingDirectoryOverlays(
bool show )
429 kdDebug(1203) <<
"KonqPropsView::setShowingDirectoryOverlays " << show << endl;
430 m_bShowDirectoryOverlays = show;
431 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
433 kdDebug(1203) <<
"Saving in default properties" << endl;
434 m_defaultProps->setShowingDirectoryOverlays( show );
436 else if (currentConfig())
438 kdDebug(1203) <<
"Saving in current config" << endl;
439 TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
440 currentConfig()->writeEntry(
"ShowDirectoryOverlays", m_bShowDirectoryOverlays );
441 currentConfig()->sync();
445 void KonqPropsView::setShowingFreeSpaceOverlays(
bool show )
447 kdDebug(1203) <<
"KonqPropsView::setShowingFreeSpaceOverlays " << show << endl;
448 m_bShowFreeSpaceOverlays = show;
449 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
451 kdDebug(1203) <<
"Saving in default properties" << endl;
452 m_defaultProps->setShowingFreeSpaceOverlays( show );
454 else if (currentConfig())
456 kdDebug(1203) <<
"Saving in current config" << endl;
457 TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
458 currentConfig()->writeEntry(
"ShowFreeSpaceOverlays", m_bShowFreeSpaceOverlays );
459 currentConfig()->sync();
463 void KonqPropsView::setShowingPreview(
const TQString &preview,
bool show )
465 if ( m_dontPreview.contains( preview ) != show )
468 m_dontPreview.remove( preview );
470 m_dontPreview.append( preview );
471 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
472 m_defaultProps->setShowingPreview( preview, show );
473 else if (currentConfig())
475 TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
479 bool audioEnabled = !m_dontPreview.contains(
"audio/");
483 m_dontPreview.remove(
"audio/");
484 currentConfig()->writeEntry(
"DontPreview", m_dontPreview );
485 currentConfig()->writeEntry(
"EnableSoundPreviews", audioEnabled );
486 currentConfig()->sync();
488 m_dontPreview.append(
"audio/");
492 delete d->previewsToShow;
493 d->previewsToShow = 0;
496 void KonqPropsView::setShowingPreview(
bool show )
498 d->previewsEnabled = show;
500 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
502 kdDebug(1203) <<
"Saving in default properties" << endl;
503 m_defaultProps-> setShowingPreview( show );
505 else if (currentConfig())
507 kdDebug(1203) <<
"Saving in current config" << endl;
508 TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
509 currentConfig()->writeEntry(
"PreviewsEnabled", d->previewsEnabled );
510 currentConfig()->sync();
513 delete d->previewsToShow;
514 d->previewsToShow = 0;
517 bool KonqPropsView::isShowingPreview()
519 return d->previewsEnabled;
522 void KonqPropsView::setBgColor(
const TQColor & color )
525 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
527 m_defaultProps->setBgColor( color );
531 TDEConfigBase * colorConfig = currentColorConfig();
534 TDEConfigGroupSaver cgs(colorConfig, currentGroup());
535 colorConfig->writeEntry(
"BgColor", m_bgColor );
541 const TQColor & KonqPropsView::bgColor( TQWidget * widget )
const
543 if ( !m_bgColor.isValid() )
544 return widget->colorGroup().base();
549 void KonqPropsView::setTextColor(
const TQColor & color )
552 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
554 m_defaultProps->setTextColor( color );
558 TDEConfigBase * colorConfig = currentColorConfig();
561 TDEConfigGroupSaver cgs(colorConfig, currentGroup());
562 colorConfig->writeEntry(
"TextColor", m_textColor );
568 const TQColor & KonqPropsView::textColor( TQWidget * widget )
const
570 if ( !m_textColor.isValid() )
571 return widget->colorGroup().text();
576 void KonqPropsView::setBgPixmapFile(
const TQString & file )
578 m_bgPixmapFile = file;
580 if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
582 m_defaultProps->setBgPixmapFile( file );
586 TDEConfigBase * colorConfig = currentColorConfig();
589 TDEConfigGroupSaver cgs(colorConfig, currentGroup());
590 colorConfig->writePathEntry(
"BgImage", file );
596 TQPixmap KonqPropsView::loadPixmap()
const
600 if ( !m_bgPixmapFile.isEmpty() )
601 bgPixmap = wallpaperPixmap( m_bgPixmapFile );
605 void KonqPropsView::applyColors(TQWidget * widget)
const
607 if ( m_bgPixmapFile.isEmpty() )
608 widget->setPaletteBackgroundColor( bgColor( widget ) );
611 TQPixmap pix = loadPixmap();
617 if ( ! pix.isNull() )
618 widget->setBackgroundPixmap( pix );
622 if ( m_textColor.isValid() )
623 widget->setPaletteForegroundColor( m_textColor );
626 const TQStringList& KonqPropsView::previewSettings()
628 if ( ! d->previewsToShow )
630 d->previewsToShow =
new TQStringList;
632 if (d->previewsEnabled) {
633 TDETrader::OfferList plugins = TDETrader::self()->query(
"ThumbCreator" );
634 for ( TDETrader::OfferList::ConstIterator it = plugins.begin(); it != plugins.end(); ++it )
636 TQString name = (*it)->desktopEntryName();
637 if ( ! m_dontPreview.contains(name) )
638 d->previewsToShow->append( name );
640 if ( ! m_dontPreview.contains(
"audio/" ) )
641 d->previewsToShow->append(
"audio/" );
645 return *(d->previewsToShow);
648 const TQString& KonqPropsView::sortCriterion()
const {
649 return d->sortcriterion;
static KonqFMSettings * settings()
The static instance of KonqFMSettings.
The class KonqPropsView holds the properties for a Konqueror View.
bool enterDir(const KURL &dir)
Called when entering a directory Checks for a .directory, read it.
KonqPropsView(TDEInstance *instance, KonqPropsView *defaultProps)
Constructs a KonqPropsView instance from an instance config file.
bool isDefaultProperties() const
Is this the instance representing default properties ?
virtual ~KonqPropsView()
Destructor.
void setSaveViewPropertiesLocally(bool value)
Turn on/off saving properties locally Don't do this on the default properties instance.