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

libkonq

  • libkonq
konq_propsview.cc
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( KInstance * 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  KConfig *config = instance->config();
84  KConfigGroupSaver 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 
98  m_dontPreview = config->readListEntry( "DontPreview" );
99  m_dontPreview.remove("audio/"); //Use the separate setting.
100  //We default to this off anyway, so it's no harm to remove this
101 
102  //The setting for sound previews is stored separately, so we can force
103  //the default-to-off bias to propagate up.
104  if (!config->readBoolEntry("EnableSoundPreviews", false))
105  {
106  if (!m_dontPreview.contains("audio/"))
107  m_dontPreview.append("audio/");
108  }
109 
110  d->previewsEnabled = config->readBoolEntry( "PreviewsEnabled", true );
111 
112  TQColor tc = KonqFMSettings::settings()->normalTextColor();
113  m_textColor = config->readColorEntry( "TextColor", &tc );
114  m_bgColor = config->readColorEntry( "BgColor" ); // will be set to TQColor() if not found
115  m_bgPixmapFile = config->readPathEntry( "BgImage" );
116  //kdDebug(1203) << "KonqPropsView::KonqPropsView from \"config\" : BgImage=" << m_bgPixmapFile << endl;
117 
118  // colorsConfig is either the local file (.directory) or the application global file
119  // (we want the same colors for all types of view)
120  // The code above reads from the view's config file, for compatibility only.
121  // So now we read the settings from the app global file, if this is the default props
122  if (!defaultProps)
123  {
124  KConfigGroupSaver cgs2(KGlobal::config(), "Settings");
125  m_textColor = KGlobal::config()->readColorEntry( "TextColor", &m_textColor );
126  m_bgColor = KGlobal::config()->readColorEntry( "BgColor", &m_bgColor );
127  m_bgPixmapFile = KGlobal::config()->readPathEntry( "BgImage", m_bgPixmapFile );
128  //kdDebug(1203) << "KonqPropsView::KonqPropsView from KGlobal : BgImage=" << m_bgPixmapFile << endl;
129  }
130 
131  KGlobal::dirs()->addResourceType("tiles",
132  KGlobal::dirs()->kde_default("data") + "konqueror/tiles/");
133 }
134 
135 bool KonqPropsView::isCaseInsensitiveSort() const
136 {
137  return d->caseInsensitiveSort;
138 }
139 
140 bool KonqPropsView::isDirsFirst() const
141 {
142  return d->dirsfirst;
143 }
144 
145 bool KonqPropsView::isDescending() const
146 {
147  return d->descending;
148 }
149 
150 KConfigBase * KonqPropsView::currentConfig()
151 {
152  if ( !m_currentConfig )
153  {
154  // 0L ? This has to be a non-default save-locally instance...
155  assert ( m_bSaveViewPropertiesLocally );
156  assert ( !isDefaultProperties() );
157 
158  if (!dotDirectory.isEmpty())
159  m_currentConfig = new KSimpleConfig( dotDirectory );
160  // the "else" is when we want to save locally but this is a remote URL -> no save
161  }
162  return m_currentConfig;
163 }
164 
165 KConfigBase * KonqPropsView::currentColorConfig()
166 {
167  // Saving locally ?
168  if ( m_bSaveViewPropertiesLocally && !isDefaultProperties() )
169  return currentConfig(); // Will create it if necessary
170  else
171  // Save color settings in app's file, not in view's file
172  return KGlobal::config();
173 }
174 
175 KonqPropsView::~KonqPropsView()
176 {
177  delete d->previewsToShow;
178  delete d;
179  d=0;
180 }
181 
182 bool KonqPropsView::enterDir( const KURL & dir )
183 {
184  //kdDebug(1203) << "enterDir " << dir.prettyURL() << endl;
185  // Can't do that with default properties
186  assert( !isDefaultProperties() );
187 
188  // Check for .directory
189  KURL u ( dir );
190  u.addPath(".directory");
191  bool dotDirExists = u.isLocalFile() && TQFile::exists( u.path() );
192  dotDirectory = u.isLocalFile() ? u.path() : TQString::null;
193 
194  // Revert to default setting first - unless there is no .directory
195  // in the previous dir nor in this one (then we can keep the current settings)
196  if (dotDirExists || m_dotDirExists)
197  {
198  m_iIconSize = m_defaultProps->iconSize();
199  m_iItemTextPos = m_defaultProps->itemTextPos();
200  d->sortcriterion = m_defaultProps->sortCriterion();
201  d->dirsfirst = m_defaultProps->isDirsFirst();
202  d->descending = m_defaultProps->isDescending();
203  m_bShowDot = m_defaultProps->isShowingDotFiles();
204  d->caseInsensitiveSort=m_defaultProps->isCaseInsensitiveSort();
205  m_dontPreview = m_defaultProps->m_dontPreview;
206  m_textColor = m_defaultProps->m_textColor;
207  m_bgColor = m_defaultProps->m_bgColor;
208  m_bgPixmapFile = m_defaultProps->bgPixmapFile();
209  }
210 
211  if (dotDirExists)
212  {
213  //kdDebug(1203) << "Found .directory file" << endl;
214  KSimpleConfig * config = new KSimpleConfig( dotDirectory, true );
215  config->setGroup("URL properties");
216 
217  m_iIconSize = config->readNumEntry( "IconSize", m_iIconSize );
218  m_iItemTextPos = config->readNumEntry( "ItemTextPos", m_iItemTextPos );
219  d->sortcriterion = config->readEntry( "SortingCriterion" , d->sortcriterion );
220  d->dirsfirst = config->readBoolEntry( "SortDirsFirst", d->dirsfirst );
221  d->descending = config->readBoolEntry( "SortDescending", d->descending );
222  m_bShowDot = config->readBoolEntry( "ShowDotFiles", m_bShowDot );
223  d->caseInsensitiveSort=config->readBoolEntry("CaseInsensitiveSort",d->caseInsensitiveSort);
224  m_bShowDirectoryOverlays = config->readBoolEntry( "ShowDirectoryOverlays", m_bShowDirectoryOverlays );
225  if (config->hasKey( "DontPreview" ))
226  {
227  m_dontPreview = config->readListEntry( "DontPreview" );
228 
229  //If the .directory file says something about sound previews,
230  //obey it, otherwise propagate the setting up from the defaults
231  //All this really should be split into a per-thumbnail setting,
232  //but that's too invasive at this point
233  if (config->hasKey("EnableSoundPreviews"))
234  {
235 
236  if (!config->readBoolEntry("EnableSoundPreviews", false))
237  if (!m_dontPreview.contains("audio/"))
238  m_dontPreview.append("audio/");
239  }
240  else
241  {
242  if (m_defaultProps->m_dontPreview.contains("audio/"))
243  if (!m_dontPreview.contains("audio/"))
244  m_dontPreview.append("audio/");
245  }
246  }
247 
248 
249 
250  m_textColor = config->readColorEntry( "TextColor", &m_textColor );
251  m_bgColor = config->readColorEntry( "BgColor", &m_bgColor );
252  m_bgPixmapFile = config->readPathEntry( "BgImage", m_bgPixmapFile );
253  //kdDebug(1203) << "KonqPropsView::enterDir m_bgPixmapFile=" << m_bgPixmapFile << endl;
254  d->previewsEnabled = config->readBoolEntry( "PreviewsEnabled", d->previewsEnabled );
255  delete config;
256  }
257  //if there is or was a .directory then the settings probably have changed
258  bool configChanged=(m_dotDirExists|| dotDirExists);
259  m_dotDirExists = dotDirExists;
260  m_currentConfig = 0L; // new dir, not current config for saving yet
261  //kdDebug(1203) << "KonqPropsView::enterDir returning " << configChanged << endl;
262  return configChanged;
263 }
264 
265 void KonqPropsView::setSaveViewPropertiesLocally( bool value )
266 {
267  assert( !isDefaultProperties() );
268  //kdDebug(1203) << "KonqPropsView::setSaveViewPropertiesLocally " << value << endl;
269 
270  if ( m_bSaveViewPropertiesLocally )
271  delete m_currentConfig; // points to a KSimpleConfig
272 
273  m_bSaveViewPropertiesLocally = value;
274  m_currentConfig = 0L; // mark as dirty
275 }
276 
277 void KonqPropsView::setIconSize( int size )
278 {
279  m_iIconSize = size;
280  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
281  m_defaultProps->setIconSize( size );
282  else if (currentConfig())
283  {
284  KConfigGroupSaver cgs(currentConfig(), currentGroup());
285  currentConfig()->writeEntry( "IconSize", m_iIconSize );
286  currentConfig()->sync();
287  }
288 }
289 
290 void KonqPropsView::setItemTextPos( int pos )
291 {
292  m_iItemTextPos = pos;
293  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
294  m_defaultProps->setItemTextPos( pos );
295  else if (currentConfig())
296  {
297  KConfigGroupSaver cgs(currentConfig(), currentGroup());
298  currentConfig()->writeEntry( "ItemTextPos", m_iItemTextPos );
299  currentConfig()->sync();
300  }
301 }
302 
303 void KonqPropsView::setSortCriterion( const TQString &criterion )
304 {
305  d->sortcriterion = criterion;
306  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
307  m_defaultProps->setSortCriterion( criterion );
308  else if (currentConfig())
309  {
310  KConfigGroupSaver cgs(currentConfig(), currentGroup());
311  currentConfig()->writeEntry( "SortingCriterion", d->sortcriterion );
312  currentConfig()->sync();
313  }
314 }
315 
316 void KonqPropsView::setDirsFirst( bool first)
317 {
318  d->dirsfirst = first;
319  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
320  m_defaultProps->setDirsFirst( first );
321  else if (currentConfig())
322  {
323  KConfigGroupSaver cgs(currentConfig(), currentGroup());
324  currentConfig()->writeEntry( "SortDirsFirst", d->dirsfirst );
325  currentConfig()->sync();
326  }
327 }
328 
329 void KonqPropsView::setDescending( bool descend)
330 {
331  d->descending = descend;
332  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
333  m_defaultProps->setDescending( descend );
334  else if (currentConfig())
335  {
336  KConfigGroupSaver cgs(currentConfig(), currentGroup());
337  currentConfig()->writeEntry( "SortDescending", d->descending );
338  currentConfig()->sync();
339  }
340 }
341 
342 void KonqPropsView::setShowingDotFiles( bool show )
343 {
344  kdDebug(1203) << "KonqPropsView::setShowingDotFiles " << show << endl;
345  m_bShowDot = show;
346  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
347  {
348  kdDebug(1203) << "Saving in default properties" << endl;
349  m_defaultProps->setShowingDotFiles( show );
350  }
351  else if (currentConfig())
352  {
353  kdDebug(1203) << "Saving in current config" << endl;
354  KConfigGroupSaver cgs(currentConfig(), currentGroup());
355  currentConfig()->writeEntry( "ShowDotFiles", m_bShowDot );
356  currentConfig()->sync();
357  }
358 }
359 
360 void KonqPropsView::setCaseInsensitiveSort( bool on )
361 {
362  kdDebug(1203) << "KonqPropsView::setCaseInsensitiveSort " << on << endl;
363  d->caseInsensitiveSort = on;
364  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
365  {
366  kdDebug(1203) << "Saving in default properties" << endl;
367  m_defaultProps->setCaseInsensitiveSort( on );
368  }
369  else if (currentConfig())
370  {
371  kdDebug(1203) << "Saving in current config" << endl;
372  KConfigGroupSaver cgs(currentConfig(), currentGroup());
373  currentConfig()->writeEntry( "CaseInsensitiveSort", d->caseInsensitiveSort );
374  currentConfig()->sync();
375  }
376 }
377 
378 void KonqPropsView::setShowingDirectoryOverlays( bool show )
379 {
380  kdDebug(1203) << "KonqPropsView::setShowingDirectoryOverlays " << show << endl;
381  m_bShowDirectoryOverlays = show;
382  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
383  {
384  kdDebug(1203) << "Saving in default properties" << endl;
385  m_defaultProps->setShowingDirectoryOverlays( show );
386  }
387  else if (currentConfig())
388  {
389  kdDebug(1203) << "Saving in current config" << endl;
390  KConfigGroupSaver cgs(currentConfig(), currentGroup());
391  currentConfig()->writeEntry( "ShowDirectoryOverlays", m_bShowDirectoryOverlays );
392  currentConfig()->sync();
393  }
394 }
395 
396 void KonqPropsView::setShowingPreview( const TQString &preview, bool show )
397 {
398  if ( m_dontPreview.contains( preview ) != show )
399  return;
400  else if ( show )
401  m_dontPreview.remove( preview );
402  else
403  m_dontPreview.append( preview );
404  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
405  m_defaultProps->setShowingPreview( preview, show );
406  else if (currentConfig())
407  {
408  KConfigGroupSaver cgs(currentConfig(), currentGroup());
409 
410  //Audio is special-cased, as we use a binary setting
411  //for it to get it to follow the defaults right.
412  bool audioEnabled = !m_dontPreview.contains("audio/");
413 
414  //Don't write it out into the DontPreview line
415  if (!audioEnabled)
416  m_dontPreview.remove("audio/");
417  currentConfig()->writeEntry( "DontPreview", m_dontPreview );
418  currentConfig()->writeEntry( "EnableSoundPreviews", audioEnabled );
419  currentConfig()->sync();
420  if (!audioEnabled)
421  m_dontPreview.append("audio/");
422 
423  }
424 
425  delete d->previewsToShow;
426  d->previewsToShow = 0;
427 }
428 
429 void KonqPropsView::setShowingPreview( bool show )
430 {
431  d->previewsEnabled = show;
432 
433  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
434  {
435  kdDebug(1203) << "Saving in default properties" << endl;
436  m_defaultProps-> setShowingPreview( show );
437  }
438  else if (currentConfig())
439  {
440  kdDebug(1203) << "Saving in current config" << endl;
441  KConfigGroupSaver cgs(currentConfig(), currentGroup());
442  currentConfig()->writeEntry( "PreviewsEnabled", d->previewsEnabled );
443  currentConfig()->sync();
444  }
445 
446  delete d->previewsToShow;
447  d->previewsToShow = 0;
448 }
449 
450 bool KonqPropsView::isShowingPreview()
451 {
452  return d->previewsEnabled;
453 }
454 
455 void KonqPropsView::setBgColor( const TQColor & color )
456 {
457  m_bgColor = color;
458  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
459  {
460  m_defaultProps->setBgColor( color );
461  }
462  else
463  {
464  KConfigBase * colorConfig = currentColorConfig();
465  if (colorConfig) // 0L when saving locally but remote URL
466  {
467  KConfigGroupSaver cgs(colorConfig, currentGroup());
468  colorConfig->writeEntry( "BgColor", m_bgColor );
469  colorConfig->sync();
470  }
471  }
472 }
473 
474 const TQColor & KonqPropsView::bgColor( TQWidget * widget ) const
475 {
476  if ( !m_bgColor.isValid() )
477  return widget->colorGroup().base();
478  else
479  return m_bgColor;
480 }
481 
482 void KonqPropsView::setTextColor( const TQColor & color )
483 {
484  m_textColor = color;
485  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
486  {
487  m_defaultProps->setTextColor( color );
488  }
489  else
490  {
491  KConfigBase * colorConfig = currentColorConfig();
492  if (colorConfig) // 0L when saving locally but remote URL
493  {
494  KConfigGroupSaver cgs(colorConfig, currentGroup());
495  colorConfig->writeEntry( "TextColor", m_textColor );
496  colorConfig->sync();
497  }
498  }
499 }
500 
501 const TQColor & KonqPropsView::textColor( TQWidget * widget ) const
502 {
503  if ( !m_textColor.isValid() )
504  return widget->colorGroup().text();
505  else
506  return m_textColor;
507 }
508 
509 void KonqPropsView::setBgPixmapFile( const TQString & file )
510 {
511  m_bgPixmapFile = file;
512 
513  if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
514  {
515  m_defaultProps->setBgPixmapFile( file );
516  }
517  else
518  {
519  KConfigBase * colorConfig = currentColorConfig();
520  if (colorConfig) // 0L when saving locally but remote URL
521  {
522  KConfigGroupSaver cgs(colorConfig, currentGroup());
523  colorConfig->writePathEntry( "BgImage", file );
524  colorConfig->sync();
525  }
526  }
527 }
528 
529 TQPixmap KonqPropsView::loadPixmap() const
530 {
531  //kdDebug(1203) << "KonqPropsView::loadPixmap " << m_bgPixmapFile << endl;
532  TQPixmap bgPixmap;
533  if ( !m_bgPixmapFile.isEmpty() )
534  bgPixmap = wallpaperPixmap( m_bgPixmapFile );
535  return bgPixmap;
536 }
537 
538 void KonqPropsView::applyColors(TQWidget * widget) const
539 {
540  if ( m_bgPixmapFile.isEmpty() )
541  widget->setPaletteBackgroundColor( bgColor( widget ) );
542  else
543  {
544  TQPixmap pix = loadPixmap();
545  // don't set an null pixmap, as this leads to
546  // undefined results with regards to the background of widgets
547  // that have the iconview as a parent and on the iconview itself
548  // e.g. the rename textedit widget when renaming a QIconViewItem
549  // Qt-issue: N64698
550  if ( ! pix.isNull() )
551  widget->setBackgroundPixmap( pix );
552  // setPaletteBackgroundPixmap leads to flicker on window activation(!)
553  }
554 
555  if ( m_textColor.isValid() )
556  widget->setPaletteForegroundColor( m_textColor );
557 }
558 
559 const TQStringList& KonqPropsView::previewSettings()
560 {
561  if ( ! d->previewsToShow )
562  {
563  d->previewsToShow = new TQStringList;
564 
565  if (d->previewsEnabled) {
566  KTrader::OfferList plugins = KTrader::self()->query( "ThumbCreator" );
567  for ( KTrader::OfferList::ConstIterator it = plugins.begin(); it != plugins.end(); ++it )
568  {
569  TQString name = (*it)->desktopEntryName();
570  if ( ! m_dontPreview.contains(name) )
571  d->previewsToShow->append( name );
572  }
573  if ( ! m_dontPreview.contains( "audio/" ) )
574  d->previewsToShow->append( "audio/" );
575  }
576  }
577 
578  return *(d->previewsToShow);
579 }
580 
581 const TQString& KonqPropsView::sortCriterion() const {
582  return d->sortcriterion;
583 }
584 

libkonq

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

libkonq

Skip menu "libkonq"
  • kate
  • kwin
  •   lib
  • libkonq
Generated for libkonq by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |