• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libkonq
 

libkonq

  • libkonq
konq_propsview.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 1998, 1999 Faure David <faure@kde.org>
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; see the file COPYING. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "konq_propsview.h"
21 #include "konq_settings.h"
22 
23 #include <kdebug.h>
24 #include <kstandarddirs.h>
25 #include <kpixmap.h>
26 #include <tqpixmapcache.h>
27 #include <tqiconview.h>
28 #include <unistd.h>
29 #include <tqfile.h>
30 #include <iostream>
31 #include <ktrader.h>
32 #include <kinstance.h>
33 #include <assert.h>
34 
35 #include <ksimpleconfig.h>
36 
37 static TQPixmap wallpaperPixmap( const TQString & _wallpaper )
38 {
39  TQString key = "wallpapers/";
40  key += _wallpaper;
41  KPixmap pix;
42 
43  if ( TQPixmapCache::find( key, pix ) )
44  return pix;
45 
46  TQString path = locate("tiles", _wallpaper);
47  if (path.isEmpty())
48  path = locate("wallpaper", _wallpaper);
49  if (!path.isEmpty())
50  {
51  // This looks really ugly, especially on an 8bit display.
52  // I'm not sure what it's good for.
53  // Anyway, if you change it here, keep konq_bgnddlg in sync (David)
54  // pix.load( path, 0, KPixmap::LowColor );
55  pix.load( path );
56  if ( pix.isNull() )
57  kdWarning(1203) << "Could not load wallpaper " << path << endl;
58  else
59  TQPixmapCache::insert( key, pix );
60  return pix;
61  } else kdWarning(1203) << "Couldn't locate wallpaper " << _wallpaper << endl;
62  return TQPixmap();
63 }
64 
65 struct KonqPropsView::Private
66 {
67  TQStringList* previewsToShow;
68  bool previewsEnabled:1;
69  bool caseInsensitiveSort:1;
70  bool dirsfirst:1;
71  bool descending:1;
72  TQString sortcriterion;
73 };
74 
75 KonqPropsView::KonqPropsView( TDEInstance * instance, KonqPropsView * defaultProps )
76  : m_bSaveViewPropertiesLocally( false ), // will be overridden by setSave... anyway
77  // if this is the default properties instance, then keep config object for saving
78  m_dotDirExists( true ), // HACK so that enterDir returns true initially
79  m_currentConfig( defaultProps ? 0L : instance->config() ),
80  m_defaultProps( defaultProps )
81 {
82 
83  TDEConfig *config = instance->config();
84  TDEConfigGroupSaver cgs(config, "Settings");
85 
86  d = new Private;
87  d->previewsToShow = 0;
88  d->caseInsensitiveSort=config->readBoolEntry( "CaseInsensitiveSort", true );
89 
90  m_iIconSize = config->readNumEntry( "IconSize", 0 );
91  m_iItemTextPos = config->readNumEntry( "ItemTextPos", TQIconView::Bottom );
92  d->sortcriterion = config->readEntry( "SortingCriterion", "sort_nci" );
93  d->dirsfirst = config->readBoolEntry( "SortDirsFirst", true );
94  d->descending = config->readBoolEntry( "SortDescending", false );
95  m_bShowDot = config->readBoolEntry( "ShowDotFiles", false );
96  m_bShowDirectoryOverlays = config->readBoolEntry( "ShowDirectoryOverlays", false );
97  m_bShowFreeSpaceOverlays = config->readBoolEntry( "ShowFreeSpaceOverlays", true );
98 
99  m_dontPreview = config->readListEntry( "DontPreview" );
100  m_dontPreview.remove("audio/"); //Use the separate setting.
101  //We default to this off anyway, so it's no harm to remove this
102 
103  //The setting for sound previews is stored separately, so we can force
104  //the default-to-off bias to propagate up.
105  if (!config->readBoolEntry("EnableSoundPreviews", false))
106  {
107  if (!m_dontPreview.contains("audio/"))
108  m_dontPreview.append("audio/");
109  }
110 
111  d->previewsEnabled = config->readBoolEntry( "PreviewsEnabled", true );
112 
113  TQColor tc = KonqFMSettings::settings()->normalTextColor();
114  m_textColor = config->readColorEntry( "TextColor", &tc );
115  m_bgColor = config->readColorEntry( "BgColor" ); // will be set to TQColor() if not found
116  m_bgPixmapFile = config->readPathEntry( "BgImage" );
117  //kdDebug(1203) << "KonqPropsView::KonqPropsView from \"config\" : BgImage=" << m_bgPixmapFile << endl;
118 
119  // colorsConfig is either the local file (.directory) or the application global file
120  // (we want the same colors for all types of view)
121  // The code above reads from the view's config file, for compatibility only.
122  // So now we read the settings from the app global file, if this is the default props
123  if (!defaultProps)
124  {
125  TDEConfigGroupSaver cgs2(TDEGlobal::config(), "Settings");
126  m_textColor = TDEGlobal::config()->readColorEntry( "TextColor", &m_textColor );
127  m_bgColor = TDEGlobal::config()->readColorEntry( "BgColor", &m_bgColor );
128  m_bgPixmapFile = TDEGlobal::config()->readPathEntry( "BgImage", m_bgPixmapFile );
129  //kdDebug(1203) << "KonqPropsView::KonqPropsView from TDEGlobal : BgImage=" << m_bgPixmapFile << endl;
130  }
131 
132  TDEGlobal::dirs()->addResourceType("tiles",
133  TDEGlobal::dirs()->kde_default("data") + "konqueror/tiles/");
134 }
135 
136 bool KonqPropsView::isCaseInsensitiveSort() const
137 {
138  return d->caseInsensitiveSort;
139 }
140 
141 bool KonqPropsView::isDirsFirst() const
142 {
143  return d->dirsfirst;
144 }
145 
146 bool KonqPropsView::isDescending() const
147 {
148  return d->descending;
149 }
150 
151 TDEConfigBase * KonqPropsView::currentConfig()
152 {
153  if ( !m_currentConfig )
154  {
155  // 0L ? This has to be a non-default save-locally instance...
156  assert ( m_bSaveViewPropertiesLocally );
157  assert ( !isDefaultProperties() );
158 
159  if (!dotDirectory.isEmpty())
160  m_currentConfig = new KSimpleConfig( dotDirectory );
161  // the "else" is when we want to save locally but this is a remote URL -> no save
162  }
163  return m_currentConfig;
164 }
165 
166 TDEConfigBase * KonqPropsView::currentColorConfig()
167 {
168  // Saving locally ?
169  if ( m_bSaveViewPropertiesLocally && !isDefaultProperties() )
170  return currentConfig(); // Will create it if necessary
171  else
172  // Save color settings in app's file, not in view's file
173  return TDEGlobal::config();
174 }
175 
176 KonqPropsView::~KonqPropsView()
177 {
178  delete d->previewsToShow;
179  delete d;
180  d=0;
181 }
182 
183 bool KonqPropsView::enterDir( const KURL & dir )
184 {
185  //kdDebug(1203) << "enterDir " << dir.prettyURL() << endl;
186  // Can't do that with default properties
187  assert( !isDefaultProperties() );
188 
189  // Check for .directory
190  KURL u ( dir );
191  u.addPath(".directory");
192  bool dotDirExists = u.isLocalFile() && TQFile::exists( u.path() );
193  dotDirectory = u.isLocalFile() ? u.path() : TQString::null;
194 
195  // Revert to default setting first - unless there is no .directory
196  // in the previous dir nor in this one (then we can keep the current settings)
197  if (dotDirExists || m_dotDirExists)
198  {
199  m_iIconSize = m_defaultProps->iconSize();
200  m_iItemTextPos = m_defaultProps->itemTextPos();
201  d->sortcriterion = m_defaultProps->sortCriterion();
202  d->dirsfirst = m_defaultProps->isDirsFirst();
203  d->descending = m_defaultProps->isDescending();
204  m_bShowDot = m_defaultProps->isShowingDotFiles();
205  d->caseInsensitiveSort=m_defaultProps->isCaseInsensitiveSort();
206  m_dontPreview = m_defaultProps->m_dontPreview;
207  m_textColor = m_defaultProps->m_textColor;
208  m_bgColor = m_defaultProps->m_bgColor;
209  m_bgPixmapFile = m_defaultProps->bgPixmapFile();
210  }
211 
212  if (dotDirExists)
213  {
214  //kdDebug(1203) << "Found .directory file" << endl;
215  KSimpleConfig * config = new KSimpleConfig( dotDirectory, true );
216  config->setGroup("URL properties");
217 
218  m_iIconSize = config->readNumEntry( "IconSize", m_iIconSize );
219  m_iItemTextPos = config->readNumEntry( "ItemTextPos", m_iItemTextPos );
220  d->sortcriterion = config->readEntry( "SortingCriterion" , d->sortcriterion );
221  d->dirsfirst = config->readBoolEntry( "SortDirsFirst", d->dirsfirst );
222  d->descending = config->readBoolEntry( "SortDescending", d->descending );
223  m_bShowDot = config->readBoolEntry( "ShowDotFiles", m_bShowDot );
224  d->caseInsensitiveSort=config->readBoolEntry("CaseInsensitiveSort",d->caseInsensitiveSort);
225  m_bShowDirectoryOverlays = config->readBoolEntry( "ShowDirectoryOverlays", m_bShowDirectoryOverlays );
226  m_bShowFreeSpaceOverlays = config->readBoolEntry( "ShowFreeSpaceOverlays", m_bShowFreeSpaceOverlays );
227  if (config->hasKey( "DontPreview" ))
228  {
229  m_dontPreview = config->readListEntry( "DontPreview" );
230 
231  //If the .directory file says something about sound previews,
232  //obey it, otherwise propagate the setting up from the defaults
233  //All this really should be split into a per-thumbnail setting,
234  //but that's too invasive at this point
235  if (config->hasKey("EnableSoundPreviews"))
236  {
237 
238  if (!config->readBoolEntry("EnableSoundPreviews", false))
239  if (!m_dontPreview.contains("audio/"))
240  m_dontPreview.append("audio/");
241  }
242  else
243  {
244  if (m_defaultProps->m_dontPreview.contains("audio/"))
245  if (!m_dontPreview.contains("audio/"))
246  m_dontPreview.append("audio/");
247  }
248  }
249 
250 
251 
252  m_textColor = config->readColorEntry( "TextColor", &m_textColor );
253  m_bgColor = config->readColorEntry( "BgColor", &m_bgColor );
254  m_bgPixmapFile = config->readPathEntry( "BgImage", m_bgPixmapFile );
255  //kdDebug(1203) << "KonqPropsView::enterDir m_bgPixmapFile=" << m_bgPixmapFile << endl;
256  d->previewsEnabled = config->readBoolEntry( "PreviewsEnabled", d->previewsEnabled );
257  delete config;
258  }
259  //if there is or was a .directory then the settings probably have changed
260  bool configChanged=(m_dotDirExists|| dotDirExists);
261  m_dotDirExists = dotDirExists;
262  m_currentConfig = 0L; // new dir, not current config for saving yet
263  //kdDebug(1203) << "KonqPropsView::enterDir returning " << configChanged << endl;
264  return configChanged;
265 }
266 
267 void KonqPropsView::setSaveViewPropertiesLocally( bool value )
268 {
269  assert( !isDefaultProperties() );
270  //kdDebug(1203) << "KonqPropsView::setSaveViewPropertiesLocally " << value << endl;
271 
272  if ( m_bSaveViewPropertiesLocally )
273  delete m_currentConfig; // points to a KSimpleConfig
274 
275  m_bSaveViewPropertiesLocally = value;
276  m_currentConfig = 0L; // mark as dirty
277 }
278 
279 void KonqPropsView::setIconSize( int size )
280 {
281  m_iIconSize = size;
282  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
283  m_defaultProps->setIconSize( size );
284  else if (currentConfig())
285  {
286  TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
287  currentConfig()->writeEntry( "IconSize", m_iIconSize );
288  currentConfig()->sync();
289  }
290 }
291 
292 void KonqPropsView::setItemTextPos( int pos )
293 {
294  m_iItemTextPos = pos;
295  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
296  m_defaultProps->setItemTextPos( pos );
297  else if (currentConfig())
298  {
299  TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
300  currentConfig()->writeEntry( "ItemTextPos", m_iItemTextPos );
301  currentConfig()->sync();
302  }
303 }
304 
305 void KonqPropsView::setSortCriterion( const TQString &criterion )
306 {
307  d->sortcriterion = criterion;
308  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
309  m_defaultProps->setSortCriterion( criterion );
310  else if (currentConfig())
311  {
312  TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
313  currentConfig()->writeEntry( "SortingCriterion", d->sortcriterion );
314  currentConfig()->sync();
315  }
316 }
317 
318 void KonqPropsView::setDirsFirst( bool first)
319 {
320  d->dirsfirst = first;
321  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
322  m_defaultProps->setDirsFirst( first );
323  else if (currentConfig())
324  {
325  TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
326  currentConfig()->writeEntry( "SortDirsFirst", d->dirsfirst );
327  currentConfig()->sync();
328  }
329 }
330 
331 void KonqPropsView::setDescending( bool descend)
332 {
333  d->descending = descend;
334  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
335  m_defaultProps->setDescending( descend );
336  else if (currentConfig())
337  {
338  TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
339  currentConfig()->writeEntry( "SortDescending", d->descending );
340  currentConfig()->sync();
341  }
342 }
343 
344 void KonqPropsView::setShowingDotFiles( bool show )
345 {
346  kdDebug(1203) << "KonqPropsView::setShowingDotFiles " << show << endl;
347  m_bShowDot = show;
348  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
349  {
350  kdDebug(1203) << "Saving in default properties" << endl;
351  m_defaultProps->setShowingDotFiles( show );
352  }
353  else if (currentConfig())
354  {
355  kdDebug(1203) << "Saving in current config" << endl;
356  TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
357  currentConfig()->writeEntry( "ShowDotFiles", m_bShowDot );
358  currentConfig()->sync();
359  }
360 }
361 
362 void KonqPropsView::setCaseInsensitiveSort( bool on )
363 {
364  kdDebug(1203) << "KonqPropsView::setCaseInsensitiveSort " << on << endl;
365  d->caseInsensitiveSort = on;
366  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
367  {
368  kdDebug(1203) << "Saving in default properties" << endl;
369  m_defaultProps->setCaseInsensitiveSort( on );
370  }
371  else if (currentConfig())
372  {
373  kdDebug(1203) << "Saving in current config" << endl;
374  TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
375  currentConfig()->writeEntry( "CaseInsensitiveSort", d->caseInsensitiveSort );
376  currentConfig()->sync();
377  }
378 }
379 
380 void KonqPropsView::setShowingDirectoryOverlays( bool show )
381 {
382  kdDebug(1203) << "KonqPropsView::setShowingDirectoryOverlays " << show << endl;
383  m_bShowDirectoryOverlays = show;
384  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
385  {
386  kdDebug(1203) << "Saving in default properties" << endl;
387  m_defaultProps->setShowingDirectoryOverlays( show );
388  }
389  else if (currentConfig())
390  {
391  kdDebug(1203) << "Saving in current config" << endl;
392  TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
393  currentConfig()->writeEntry( "ShowDirectoryOverlays", m_bShowDirectoryOverlays );
394  currentConfig()->sync();
395  }
396 }
397 
398 void KonqPropsView::setShowingFreeSpaceOverlays( bool show )
399 {
400  kdDebug(1203) << "KonqPropsView::setShowingFreeSpaceOverlays " << show << endl;
401  m_bShowFreeSpaceOverlays = show;
402  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
403  {
404  kdDebug(1203) << "Saving in default properties" << endl;
405  m_defaultProps->setShowingFreeSpaceOverlays( show );
406  }
407  else if (currentConfig())
408  {
409  kdDebug(1203) << "Saving in current config" << endl;
410  TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
411  currentConfig()->writeEntry( "ShowFreeSpaceOverlays", m_bShowFreeSpaceOverlays );
412  currentConfig()->sync();
413  }
414 }
415 
416 void KonqPropsView::setShowingPreview( const TQString &preview, bool show )
417 {
418  if ( m_dontPreview.contains( preview ) != show )
419  return;
420  else if ( show )
421  m_dontPreview.remove( preview );
422  else
423  m_dontPreview.append( preview );
424  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
425  m_defaultProps->setShowingPreview( preview, show );
426  else if (currentConfig())
427  {
428  TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
429 
430  //Audio is special-cased, as we use a binary setting
431  //for it to get it to follow the defaults right.
432  bool audioEnabled = !m_dontPreview.contains("audio/");
433 
434  //Don't write it out into the DontPreview line
435  if (!audioEnabled)
436  m_dontPreview.remove("audio/");
437  currentConfig()->writeEntry( "DontPreview", m_dontPreview );
438  currentConfig()->writeEntry( "EnableSoundPreviews", audioEnabled );
439  currentConfig()->sync();
440  if (!audioEnabled)
441  m_dontPreview.append("audio/");
442 
443  }
444 
445  delete d->previewsToShow;
446  d->previewsToShow = 0;
447 }
448 
449 void KonqPropsView::setShowingPreview( bool show )
450 {
451  d->previewsEnabled = show;
452 
453  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
454  {
455  kdDebug(1203) << "Saving in default properties" << endl;
456  m_defaultProps-> setShowingPreview( show );
457  }
458  else if (currentConfig())
459  {
460  kdDebug(1203) << "Saving in current config" << endl;
461  TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
462  currentConfig()->writeEntry( "PreviewsEnabled", d->previewsEnabled );
463  currentConfig()->sync();
464  }
465 
466  delete d->previewsToShow;
467  d->previewsToShow = 0;
468 }
469 
470 bool KonqPropsView::isShowingPreview()
471 {
472  return d->previewsEnabled;
473 }
474 
475 void KonqPropsView::setBgColor( const TQColor & color )
476 {
477  m_bgColor = color;
478  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
479  {
480  m_defaultProps->setBgColor( color );
481  }
482  else
483  {
484  TDEConfigBase * colorConfig = currentColorConfig();
485  if (colorConfig) // 0L when saving locally but remote URL
486  {
487  TDEConfigGroupSaver cgs(colorConfig, currentGroup());
488  colorConfig->writeEntry( "BgColor", m_bgColor );
489  colorConfig->sync();
490  }
491  }
492 }
493 
494 const TQColor & KonqPropsView::bgColor( TQWidget * widget ) const
495 {
496  if ( !m_bgColor.isValid() )
497  return widget->colorGroup().base();
498  else
499  return m_bgColor;
500 }
501 
502 void KonqPropsView::setTextColor( const TQColor & color )
503 {
504  m_textColor = color;
505  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
506  {
507  m_defaultProps->setTextColor( color );
508  }
509  else
510  {
511  TDEConfigBase * colorConfig = currentColorConfig();
512  if (colorConfig) // 0L when saving locally but remote URL
513  {
514  TDEConfigGroupSaver cgs(colorConfig, currentGroup());
515  colorConfig->writeEntry( "TextColor", m_textColor );
516  colorConfig->sync();
517  }
518  }
519 }
520 
521 const TQColor & KonqPropsView::textColor( TQWidget * widget ) const
522 {
523  if ( !m_textColor.isValid() )
524  return widget->colorGroup().text();
525  else
526  return m_textColor;
527 }
528 
529 void KonqPropsView::setBgPixmapFile( const TQString & file )
530 {
531  m_bgPixmapFile = file;
532 
533  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
534  {
535  m_defaultProps->setBgPixmapFile( file );
536  }
537  else
538  {
539  TDEConfigBase * colorConfig = currentColorConfig();
540  if (colorConfig) // 0L when saving locally but remote URL
541  {
542  TDEConfigGroupSaver cgs(colorConfig, currentGroup());
543  colorConfig->writePathEntry( "BgImage", file );
544  colorConfig->sync();
545  }
546  }
547 }
548 
549 TQPixmap KonqPropsView::loadPixmap() const
550 {
551  //kdDebug(1203) << "KonqPropsView::loadPixmap " << m_bgPixmapFile << endl;
552  TQPixmap bgPixmap;
553  if ( !m_bgPixmapFile.isEmpty() )
554  bgPixmap = wallpaperPixmap( m_bgPixmapFile );
555  return bgPixmap;
556 }
557 
558 void KonqPropsView::applyColors(TQWidget * widget) const
559 {
560  if ( m_bgPixmapFile.isEmpty() )
561  widget->setPaletteBackgroundColor( bgColor( widget ) );
562  else
563  {
564  TQPixmap pix = loadPixmap();
565  // don't set an null pixmap, as this leads to
566  // undefined results with regards to the background of widgets
567  // that have the iconview as a parent and on the iconview itself
568  // e.g. the rename textedit widget when renaming a QIconViewItem
569  // Qt-issue: N64698
570  if ( ! pix.isNull() )
571  widget->setBackgroundPixmap( pix );
572  // setPaletteBackgroundPixmap leads to flicker on window activation(!)
573  }
574 
575  if ( m_textColor.isValid() )
576  widget->setPaletteForegroundColor( m_textColor );
577 }
578 
579 const TQStringList& KonqPropsView::previewSettings()
580 {
581  if ( ! d->previewsToShow )
582  {
583  d->previewsToShow = new TQStringList;
584 
585  if (d->previewsEnabled) {
586  TDETrader::OfferList plugins = TDETrader::self()->query( "ThumbCreator" );
587  for ( TDETrader::OfferList::ConstIterator it = plugins.begin(); it != plugins.end(); ++it )
588  {
589  TQString name = (*it)->desktopEntryName();
590  if ( ! m_dontPreview.contains(name) )
591  d->previewsToShow->append( name );
592  }
593  if ( ! m_dontPreview.contains( "audio/" ) )
594  d->previewsToShow->append( "audio/" );
595  }
596  }
597 
598  return *(d->previewsToShow);
599 }
600 
601 const TQString& KonqPropsView::sortCriterion() const {
602  return d->sortcriterion;
603 }
604 

libkonq

Skip menu "libkonq"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libkonq

Skip menu "libkonq"
  • kate
  • libkonq
  • twin
  •   lib
Generated for libkonq by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.