• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kio/kfile
 

kio/kfile

  • kio
  • kfile
kimagefilepreview.cpp
1 /*
2  * This file is part of the KDE project
3  * Copyright (C) 2001 Martin R. Jones <mjones@kde.org>
4  * 2001 Carsten Pfeiffer <pfeiffer@kde.org>
5  *
6  * You can Freely distribute this program under the GNU Library General Public
7  * License. See the file "COPYING" for the exact licensing terms.
8  */
9 
10 #include <tqlayout.h>
11 #include <tqlabel.h>
12 #include <tqcombobox.h>
13 #include <tqcheckbox.h>
14 #include <tqwhatsthis.h>
15 #include <tqtimer.h>
16 
17 #include <kapplication.h>
18 #include <kconfig.h>
19 #include <kglobal.h>
20 #include <kiconloader.h>
21 #include <kpushbutton.h>
22 #include <kstandarddirs.h>
23 #include <kdebug.h>
24 #include <klocale.h>
25 #include <kfiledialog.h>
26 #include <kfileitem.h>
27 #include <kio/previewjob.h>
28 
29 #include "kimagefilepreview.h"
30 #include "config-kfile.h"
31 
32 /**** KImageFilePreview ****/
33 
34 KImageFilePreview::KImageFilePreview( TQWidget *parent )
35  : KPreviewWidgetBase( parent ),
36  m_job( 0L )
37 {
38  KConfig *config = KGlobal::config();
39  KConfigGroupSaver cs( config, ConfigGroup );
40  autoMode = config->readBoolEntry( "Automatic Preview", true );
41 
42  TQVBoxLayout *vb = new TQVBoxLayout( this, 0, KDialog::spacingHint() );
43 
44  imageLabel = new TQLabel( this );
45  imageLabel->setFrameStyle( TQFrame::NoFrame );
46  imageLabel->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
47  imageLabel->setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Expanding) );
48  vb->addWidget( imageLabel );
49 
50  TQHBoxLayout *hb = new TQHBoxLayout( 0 );
51  vb->addLayout( hb );
52 
53  autoPreview = new TQCheckBox( i18n("&Automatic preview"), this );
54  autoPreview->setChecked( autoMode );
55  hb->addWidget( autoPreview );
56  connect( autoPreview, TQT_SIGNAL(toggled(bool)), TQT_SLOT(toggleAuto(bool)) );
57 
58  previewButton = new KPushButton( SmallIconSet("thumbnail"), i18n("&Preview"), this );
59  hb->addWidget( previewButton );
60  connect( previewButton, TQT_SIGNAL(clicked()), TQT_SLOT(showPreview()) );
61 
62  timer = new TQTimer( this );
63  connect( timer, TQT_SIGNAL(timeout()), TQT_SLOT(showPreview()) );
64 
65  setSupportedMimeTypes( KIO::PreviewJob::supportedMimeTypes() );
66 }
67 
68 KImageFilePreview::~KImageFilePreview()
69 {
70  if ( m_job )
71  m_job->kill();
72 
73  KConfig *config = KGlobal::config();
74  KConfigGroupSaver cs( config, ConfigGroup );
75  config->writeEntry( "Automatic Preview", autoPreview->isChecked() );
76 }
77 
78 void KImageFilePreview::showPreview()
79 {
80  // Pass a copy since clearPreview() will clear currentURL
81  KURL url = currentURL;
82  showPreview( url, true );
83 }
84 
85 // called via KPreviewWidgetBase interface
86 void KImageFilePreview::showPreview( const KURL& url )
87 {
88  showPreview( url, false );
89 }
90 
91 void KImageFilePreview::showPreview( const KURL &url, bool force )
92 {
93  if ( !url.isValid() ) {
94  clearPreview();
95  return;
96  }
97 
98  if ( url != currentURL || force )
99  {
100  clearPreview();
101  currentURL = url;
102 
103  if ( autoMode || force )
104  {
105  int w = imageLabel->contentsRect().width() - 4;
106  int h = imageLabel->contentsRect().height() - 4;
107 
108  m_job = createJob( url, w, h );
109  if ( force ) // explicitly requested previews shall always be generated!
110  m_job->setIgnoreMaximumSize( true );
111 
112  connect( m_job, TQT_SIGNAL( result( KIO::Job * )),
113  this, TQT_SLOT( slotResult( KIO::Job * )));
114  connect( m_job, TQT_SIGNAL( gotPreview( const KFileItem*,
115  const TQPixmap& )),
116  TQT_SLOT( gotPreview( const KFileItem*, const TQPixmap& ) ));
117 
118  connect( m_job, TQT_SIGNAL( failed( const KFileItem* )),
119  this, TQT_SLOT( slotFailed( const KFileItem* ) ));
120  }
121  }
122 }
123 
124 void KImageFilePreview::toggleAuto( bool a )
125 {
126  autoMode = a;
127  if ( autoMode )
128  {
129  // Pass a copy since clearPreview() will clear currentURL
130  KURL url = currentURL;
131  showPreview( url, true );
132  }
133 }
134 
135 void KImageFilePreview::resizeEvent( TQResizeEvent * )
136 {
137  timer->start( 100, true ); // forces a new preview
138 }
139 
140 TQSize KImageFilePreview::sizeHint() const
141 {
142  return TQSize( 20, 200 ); // otherwise it ends up huge???
143 }
144 
145 KIO::PreviewJob * KImageFilePreview::createJob( const KURL& url, int w, int h )
146 {
147  KURL::List urls;
148  urls.append( url );
149  return KIO::filePreview( urls, w, h, 0, 0, true, false );
150 }
151 
152 void KImageFilePreview::gotPreview( const KFileItem* item, const TQPixmap& pm )
153 {
154  if ( item->url() == currentURL ) // should always be the case
155  imageLabel->setPixmap( pm );
156 }
157 
158 void KImageFilePreview::slotFailed( const KFileItem* item )
159 {
160  if ( item->isDir() )
161  imageLabel->clear();
162  else if ( item->url() == currentURL ) // should always be the case
163  imageLabel->setPixmap( SmallIcon( "file_broken", KIcon::SizeLarge,
164  KIcon::DisabledState ));
165 }
166 
167 void KImageFilePreview::slotResult( KIO::Job *job )
168 {
169  if ( job == m_job )
170  m_job = 0L;
171 }
172 
173 void KImageFilePreview::clearPreview()
174 {
175  if ( m_job ) {
176  m_job->kill();
177  m_job = 0L;
178  }
179 
180  imageLabel->clear();
181  currentURL = KURL();
182 }
183 
184 void KImageFilePreview::virtual_hook( int id, void* data )
185 { KPreviewWidgetBase::virtual_hook( id, data ); }
186 
187 #include "kimagefilepreview.moc"
KPreviewWidgetBase
Abstract baseclass for all preview widgets which shall be used via KFileDialog::setPreviewWidget(cons...
Definition: kpreviewwidgetbase.h:44

kio/kfile

Skip menu "kio/kfile"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kio/kfile

Skip menu "kio/kfile"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kio/kfile by doxygen 1.8.13
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |