• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdefile
 

tdeio/tdefile

  • tdeio
  • tdefile
kurlbar.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2001,2002,2003 Carsten Pfeiffer <pfeiffer@kde.org>
3 
4  library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation, version 2.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include <unistd.h>
20 
21 #include <tqapplication.h>
22 #include <tqcheckbox.h>
23 #include <tqdrawutil.h>
24 #include <tqfontmetrics.h>
25 #include <tqlabel.h>
26 #include <tqgrid.h>
27 #include <tqpainter.h>
28 #include <tqpopupmenu.h>
29 #include <tqstyle.h>
30 #include <tqvbox.h>
31 #include <tqwhatsthis.h>
32 
33 #include <tdeaboutdata.h>
34 #include <tdeconfig.h>
35 #include <kdebug.h>
36 #include <tdeglobal.h>
37 #include <kicondialog.h>
38 #include <kiconloader.h>
39 #include <kinstance.h>
40 #include <klineedit.h>
41 #include <tdelocale.h>
42 #include <kmimetype.h>
43 #include <kprotocolinfo.h>
44 #include <kstringhandler.h>
45 #include <kurldrag.h>
46 #include <kurlrequester.h>
47 #include <tdeio/global.h>
48 #include <tdeio/netaccess.h>
49 
50 #include "kurlbar.h"
51 
56 class KURLBarToolTip : public TQToolTip
57 {
58 public:
59  KURLBarToolTip( TQListBox *view ) : TQToolTip( view ), m_view( view ) {}
60 
61 protected:
62  virtual void maybeTip( const TQPoint& point ) {
63  TQListBoxItem *item = m_view->itemAt( point );
64  if ( item ) {
65  TQString text = static_cast<KURLBarItem*>( item )->toolTip();
66  if ( !text.isEmpty() )
67  tip( m_view->itemRect( item ), text );
68  }
69  }
70 
71 private:
72  TQListBox *m_view;
73 };
74 
75 
78 
79 class KURLBarItem::KURLBarItemPrivate
80 {
81 public:
82  KURLBarItemPrivate()
83  {
84  isPersistent = true;
85  }
86 
87  bool isPersistent;
88 };
89 
90 KURLBarItem::KURLBarItem( KURLBar *parent,
91  const KURL& url, bool persistent, const TQString& description,
92  const TQString& icon, TDEIcon::Group group )
93  : TQListBoxPixmap( TDEIconLoader::unknown() /*, parent->listBox()*/ ),
94  m_url( url ),
95  m_pixmap( 0L ),
96  m_parent( parent ),
97  m_appLocal( false )
98 {
99  init( icon, group, description, persistent );
100 }
101 
102 KURLBarItem::KURLBarItem( KURLBar *parent,
103  const KURL& url, const TQString& description,
104  const TQString& icon, TDEIcon::Group group )
105  : TQListBoxPixmap( TDEIconLoader::unknown() /*, parent->listBox()*/ ),
106  m_url( url ),
107  m_pixmap( 0L ),
108  m_parent( parent ),
109  m_appLocal( false )
110 {
111  init( icon, group, description, true /*persistent*/ );
112 }
113 
114 void KURLBarItem::init( const TQString& icon, TDEIcon::Group group,
115  const TQString& description, bool persistent )
116 {
117  d = new KURLBarItemPrivate;
118  d->isPersistent = persistent;
119 
120  setCustomHighlighting( true );
121  setIcon( icon, group );
122  setDescription( description );
123 }
124 
125 KURLBarItem::~KURLBarItem()
126 {
127  delete d;
128 }
129 
130 void KURLBarItem::setURL( const KURL& url )
131 {
132  m_url = url;
133  if ( m_description.isEmpty() )
134  setText( url.fileName() );
135 }
136 
137 void KURLBarItem::setIcon( const TQString& icon, TDEIcon::Group group )
138 {
139  m_icon = icon;
140  m_group = group;
141 
142  if ( icon.isEmpty() )
143  m_pixmap = KMimeType::pixmapForURL( m_url, 0, group, iconSize() );
144  else
145  m_pixmap = TDEGlobal::iconLoader()->loadIcon( icon, group, iconSize(),
146  TDEIcon::DefaultState );
147 }
148 
149 void KURLBarItem::setDescription( const TQString& desc )
150 {
151  m_description = desc;
152  setText( desc.isEmpty() ? m_url.fileName() : desc );
153 }
154 
155 void KURLBarItem::setApplicationLocal( bool local )
156 {
157  if ( !local && !isPersistent() )
158  {
159  kdWarning() << "KURLBar: dynamic (non-persistent) items can not be global." << endl;
160  return;
161  }
162 
163  m_appLocal = local;
164 }
165 
166 void KURLBarItem::setToolTip( const TQString& tip )
167 {
168  m_toolTip = tip;
169 }
170 
171 TQString KURLBarItem::toolTip() const
172 {
173  return m_toolTip.isEmpty() ? m_url.prettyURL() : m_toolTip;
174 }
175 
176 int KURLBarItem::iconSize() const
177 {
178  return m_parent->iconSize();
179 }
180 
181 void KURLBarItem::paint( TQPainter *p )
182 {
183  TQListBox *box = listBox();
184  int w = width( box );
185  static const int margin = KDialog::spacingHint();
186 
187  // draw sunken selection
188  if ( isCurrent() || isSelected() ) {
189  int h = height( box );
190 
191  TQBrush brush = box->colorGroup().brush( TQColorGroup::Highlight );
192  p->fillRect( 0, 0, w, h, brush );
193  TQPen pen = p->pen();
194  TQPen oldPen = pen;
195  pen.setColor( box->colorGroup().mid() );
196  p->setPen( pen );
197 
198  p->drawPoint( 0, 0 );
199  p->drawPoint( 0, h - 1 );
200  p->drawPoint( w - 1, 0 );
201  p->drawPoint( w - 1, h - 1 );
202 
203  p->setPen( oldPen );
204  }
205 
206  if ( m_parent->iconSize() < TDEIcon::SizeMedium ) {
207  // small icon -> draw icon next to text
208 
209  // ### mostly cut & paste of TQListBoxPixmap::paint() until Qt 3.1
210  // (where it will properly use pixmap() instead of the internal pixmap)
211  const TQPixmap *pm = pixmap();
212  int yPos = TQMAX( 0, (height(box) - pm->height())/2 );
213 
214  p->drawPixmap( margin, yPos, *pm );
215  if ( !text().isEmpty() ) {
216  TQFontMetrics fm = p->fontMetrics();
217  if ( pm->height() < fm.height() ) {
218  yPos = fm.ascent() + fm.leading()/2;
219  }
220  else {
221  yPos = height(box)/2 - fm.height()/2 + fm.ascent() - margin;
222  }
223 
224  yPos += margin;
225  int stringWidth = box->width() - pm->width() - 2 - (margin * 2);
226  TQString visibleText = KStringHandler::rPixelSqueeze( text(), fm, stringWidth );
227  int xPos = pm->width() + margin + 2;
228 
229  if ( isCurrent() || isSelected() ) {
230  p->setPen( box->colorGroup().highlight().dark(115) );
231  p->drawText( xPos + ( TQApplication::reverseLayout() ? -1 : 1),
232  yPos + 1, visibleText );
233  p->setPen( box->colorGroup().highlightedText() );
234  }
235 
236  p->drawText( xPos, yPos, visibleText );
237  }
238  // end cut & paste (modulo pixmap centering)
239  }
240 
241  else {
242  // big icons -> draw text below icon
243  int y = margin;
244  const TQPixmap *pm = pixmap();
245 
246  if ( !pm->isNull() ) {
247  int x = (w - pm->width()) / 2;
248  x = TQMAX( x, margin );
249  p->drawPixmap( x, y, *pm );
250  }
251 
252  if ( !text().isEmpty() ) {
253  TQFontMetrics fm = p->fontMetrics();
254  y += pm->height() + fm.height() - fm.descent();
255 
256  int stringWidth = box->width() - (margin * 2);
257  TQString visibleText = KStringHandler::rPixelSqueeze( text(), fm, stringWidth );
258  int x = (w - fm.width( visibleText )) / 2;
259  x = TQMAX( x, margin );
260 
261  if ( isCurrent() || isSelected() ) {
262  p->setPen( box->colorGroup().highlight().dark(115) );
263  p->drawText( x + ( TQApplication::reverseLayout() ? -1 : 1),
264  y + 1, visibleText );
265  p->setPen( box->colorGroup().highlightedText() );
266  }
267 
268  p->drawText( x, y, visibleText );
269  }
270  }
271 }
272 
273 TQSize KURLBarItem::sizeHint() const
274 {
275  int wmin = 0;
276  int hmin = 0;
277  const KURLBarListBox *lb =static_cast<const KURLBarListBox*>(listBox());
278 
279  if ( m_parent->iconSize() < TDEIcon::SizeMedium ) {
280  wmin = TQListBoxPixmap::width( lb ) + KDialog::spacingHint() * 2;
281  hmin = TQListBoxPixmap::height( lb ) + KDialog::spacingHint() * 2;
282  }
283  else {
284  wmin = TQMAX(lb->fontMetrics().width(text()), pixmap()->width()) + KDialog::spacingHint() * 2;
285  hmin = lb->fontMetrics().lineSpacing() + pixmap()->height() + KDialog::spacingHint() * 2;
286  }
287 
288  if ( lb->isVertical() )
289  wmin = TQMIN( wmin, lb->viewport()->sizeHint().width() );
290  else
291  hmin = TQMIN( hmin, lb->viewport()->sizeHint().height() );
292 
293  return TQSize( wmin, hmin );
294 }
295 
296 int KURLBarItem::width( const TQListBox *lb ) const
297 {
298  if ( static_cast<const KURLBarListBox *>( lb )->isVertical() )
299  return TQMAX( sizeHint().width(), lb->viewport()->width() );
300  else
301  return sizeHint().width();
302 }
303 
304 int KURLBarItem::height( const TQListBox *lb ) const
305 {
306  if ( static_cast<const KURLBarListBox *>( lb )->isVertical() )
307  return sizeHint().height();
308  else
309  return TQMAX( sizeHint().height(), lb->viewport()->height() );
310 }
311 
312 bool KURLBarItem::isPersistent() const
313 {
314  return d->isPersistent;
315 }
316 
319 
320 class KURLBar::KURLBarPrivate
321 {
322 public:
323  KURLBarPrivate()
324  {
325  currentURL.setPath( TQDir::homeDirPath() );
326  defaultIconSize = 0;
327  }
328 
329  int defaultIconSize;
330  KURL currentURL;
331 };
332 
333 
334 KURLBar::KURLBar( bool useGlobalItems, TQWidget *parent, const char *name, WFlags f )
335  : TQFrame( parent, name, f ),
336  m_activeItem( 0L ),
337  m_useGlobal( useGlobalItems ),
338  m_isModified( false ),
339  m_isImmutable( false ),
340  m_listBox( 0L ),
341  m_iconSize( TDEIcon::SizeMedium )
342 {
343  d = new KURLBarPrivate();
344 
345  setListBox( 0L );
346  setSizePolicy( TQSizePolicy( isVertical() ?
347  TQSizePolicy::Maximum :
348  TQSizePolicy::Preferred,
349  isVertical() ?
350  TQSizePolicy::Preferred :
351  TQSizePolicy::Maximum ));
352  TQWhatsThis::add(this, i18n("<qt>The <b>Quick Access</b> panel provides easy access to commonly used file locations.<p>"
353  "Clicking on one of the shortcut entries will take you to that location.<p>"
354  "By right clicking on an entry you can add, edit and remove shortcuts.</qt>"));
355 }
356 
357 KURLBar::~KURLBar()
358 {
359  delete d;
360 }
361 
362 KURLBarItem * KURLBar::insertItem(const KURL& url, const TQString& description,
363  bool applicationLocal,
364  const TQString& icon, TDEIcon::Group group )
365 {
366  KURLBarItem *item = new KURLBarItem(this, url, description, icon, group);
367  item->setApplicationLocal( applicationLocal );
368  m_listBox->insertItem( item );
369  return item;
370 }
371 
372 KURLBarItem * KURLBar::insertDynamicItem(const KURL& url, const TQString& description,
373  const TQString& icon, TDEIcon::Group group )
374 {
375  KURLBarItem *item = new KURLBarItem(this, url, false, description, icon, group);
376  m_listBox->insertItem( item );
377  return item;
378 }
379 
380 void KURLBar::setOrientation( TQt::Orientation orient )
381 {
382  m_listBox->setOrientation( orient );
383  setSizePolicy( TQSizePolicy( isVertical() ?
384  TQSizePolicy::Maximum :
385  TQSizePolicy::Preferred,
386  isVertical() ?
387  TQSizePolicy::Preferred :
388  TQSizePolicy::Maximum ));
389 }
390 
391 TQt::Orientation KURLBar::orientation() const
392 {
393  return m_listBox->orientation();
394 }
395 
396 void KURLBar::setListBox( KURLBarListBox *view )
397 {
398  delete m_listBox;
399 
400  if ( !view ) {
401  m_listBox = new KURLBarListBox( this, "urlbar listbox" );
402  setOrientation( TQt::Vertical );
403  }
404  else {
405  m_listBox = view;
406  if ( m_listBox->parentWidget() != this )
407  m_listBox->reparent( this, TQPoint(0,0) );
408  m_listBox->resize( width(), height() );
409  }
410 
411  m_listBox->setSelectionMode( TDEListBox::Single );
412  paletteChange( palette() );
413  m_listBox->setFocusPolicy( TQWidget::TabFocus );
414 
415  connect( m_listBox, TQ_SIGNAL( mouseButtonClicked( int, TQListBoxItem *, const TQPoint & ) ),
416  TQ_SLOT( slotSelected( int, TQListBoxItem * )));
417  connect( m_listBox, TQ_SIGNAL( dropped( TQDropEvent * )),
418  this, TQ_SLOT( slotDropped( TQDropEvent * )));
419  connect( m_listBox, TQ_SIGNAL( contextMenuRequested( TQListBoxItem *,
420  const TQPoint& )),
421  TQ_SLOT( slotContextMenuRequested( TQListBoxItem *, const TQPoint& )));
422  connect( m_listBox, TQ_SIGNAL( returnPressed( TQListBoxItem * ) ),
423  TQ_SLOT( slotSelected( TQListBoxItem * ) ));
424 }
425 
426 void KURLBar::setIconSize( int size )
427 {
428  if ( size == m_iconSize )
429  return;
430 
431  m_iconSize = size;
432 
433  // reload the icons with the new size
434  KURLBarItem *item = static_cast<KURLBarItem*>( m_listBox->firstItem() );
435  while ( item ) {
436  item->setIcon( item->icon(), item->iconGroup() );
437  item = static_cast<KURLBarItem*>( item->next() );
438  }
439 
440  resize( sizeHint() );
441  updateGeometry();
442 }
443 
444 void KURLBar::clear()
445 {
446  m_listBox->clear();
447 }
448 
449 void KURLBar::resizeEvent( TQResizeEvent *e )
450 {
451  TQFrame::resizeEvent( e );
452  m_listBox->resize( width(), height() );
453 }
454 
455 void KURLBar::paletteChange( const TQPalette & )
456 {
457  TQPalette pal = palette();
458  TQColor gray = pal.color( TQPalette::Active, TQColorGroup::Background );
459  TQColor selectedTextColor = pal.color( TQPalette::Active, TQColorGroup::BrightText );
460  TQColor foreground = pal.color( TQPalette::Active, TQColorGroup::Foreground );
461  pal.setColor( TQPalette::Active, TQColorGroup::Base, gray );
462  pal.setColor( TQPalette::Active, TQColorGroup::HighlightedText, selectedTextColor );
463  pal.setColor( TQPalette::Active, TQColorGroup::Text, foreground );
464  pal.setColor( TQPalette::Inactive, TQColorGroup::Base, gray );
465  pal.setColor( TQPalette::Inactive, TQColorGroup::HighlightedText, selectedTextColor );
466  pal.setColor( TQPalette::Inactive, TQColorGroup::Text, foreground );
467 
468  setPalette( pal );
469 }
470 
471 TQSize KURLBar::sizeHint() const
472 {
473  return m_listBox->sizeHint();
474 
475 #if 0
476  // this code causes vertical and or horizontal scrollbars appearing
477  // depending on the text, font, moonphase and earth rotation. Just using
478  // m_listBox->sizeHint() fixes this (although the widget can then be
479  // resized to a smaller size so that scrollbars appear).
480  int w = 0;
481  int h = 0;
482  KURLBarItem *item;
483  bool vertical = isVertical();
484 
485  for ( item = static_cast<KURLBarItem*>( m_listBox->firstItem() );
486  item;
487  item = static_cast<KURLBarItem*>( item->next() ) ) {
488 
489  TQSize sh = item->sizeHint();
490 
491  if ( vertical ) {
492  w = TQMAX( w, sh.width() );
493  h += sh.height();
494  }
495  else {
496  w += sh.width();
497  h = TQMAX( h, sh.height() );
498  }
499  }
500 
501 // if ( vertical && m_listBox->verticalScrollBar()->isVisible() )
502 // w += m_listBox->verticalScrollBar()->width();
503 // else if ( !vertical && m_listBox->horizontalScrollBar()->isVisible() )
504 // h += m_listBox->horizontalScrollBar()->height();
505 
506  if ( w == 0 && h == 0 )
507  return TQSize( 100, 200 );
508  else
509  return TQSize( 6 + w, h );
510 #endif
511 }
512 
513 TQSize KURLBar::minimumSizeHint() const
514 {
515  TQSize s = sizeHint(); // ###
516  int w = s.width() + m_listBox->verticalScrollBar()->width();
517  int h = s.height() + m_listBox->horizontalScrollBar()->height();
518  return TQSize( w, h );
519 }
520 
521 void KURLBar::slotSelected( int button, TQListBoxItem *item )
522 {
523  if ( button != TQt::LeftButton )
524  return;
525 
526  slotSelected( item );
527 }
528 
529 void KURLBar::slotSelected( TQListBoxItem *item )
530 {
531  if ( item && item != m_activeItem )
532  m_activeItem = static_cast<KURLBarItem*>( item );
533 
534  if ( m_activeItem ) {
535  m_listBox->setCurrentItem( m_activeItem );
536  emit activated( m_activeItem->url() );
537  }
538 }
539 
540 void KURLBar::setCurrentItem( const KURL& url )
541 {
542  d->currentURL = url;
543 
544  TQString u = url.url(-1);
545 
546  if ( m_activeItem && m_activeItem->url().url(-1) == u )
547  return;
548 
549  bool hasURL = false;
550  TQListBoxItem *item = m_listBox->firstItem();
551  while ( item ) {
552  if ( static_cast<KURLBarItem*>( item )->url().url(-1) == u ) {
553  m_activeItem = static_cast<KURLBarItem*>( item );
554  m_listBox->setCurrentItem( item );
555  m_listBox->setSelected( item, true );
556  hasURL = true;
557  break;
558  }
559  item = item->next();
560  }
561 
562  if ( !hasURL ) {
563  m_activeItem = 0L;
564  m_listBox->clearSelection();
565  }
566 }
567 
568 KURLBarItem * KURLBar::currentItem() const
569 {
570  TQListBoxItem *item = m_listBox->item( m_listBox->currentItem() );
571  if ( item )
572  return static_cast<KURLBarItem *>( item );
573  return 0L;
574 }
575 
576 KURL KURLBar::currentURL() const
577 {
578  KURLBarItem *item = currentItem();
579  return item ? item->url() : KURL();
580 }
581 
582 void KURLBar::readConfig( TDEConfig *appConfig, const TQString& itemGroup )
583 {
584  m_isImmutable = appConfig->groupIsImmutable( itemGroup );
585  TDEConfigGroupSaver cs( appConfig, itemGroup );
586  d->defaultIconSize = m_iconSize;
587  m_iconSize = appConfig->readNumEntry( "Speedbar IconSize", m_iconSize );
588 
589  if ( m_useGlobal ) { // read global items
590  TDEConfig *globalConfig = TDEGlobal::config();
591  TDEConfigGroupSaver cs( globalConfig, (TQString)(itemGroup +" (Global)"));
592  int num = globalConfig->readNumEntry( "Number of Entries" );
593  for ( int i = 0; i < num; i++ ) {
594  readItem( i, globalConfig, false );
595  }
596  }
597 
598  // read application local items
599  int num = appConfig->readNumEntry( "Number of Entries" );
600  for ( int i = 0; i < num; i++ ) {
601  readItem( i, appConfig, true );
602  }
603 }
604 
605 void KURLBar::readItem( int i, TDEConfig *config, bool applicationLocal )
606 {
607  TQString number = TQString::number( i );
608  KURL url = KURL::fromPathOrURL( config->readPathEntry( TQString("URL_") + number ));
609  if ( !url.isValid() || !KProtocolInfo::isKnownProtocol( url ))
610  return; // nothing we could do.
611 
612  TQString description = config->readEntry( TQString("Description_") + number );
613 
614  insertItem( url,
615  description,
616  applicationLocal,
617  config->readEntry( TQString("Icon_") + number ),
618  static_cast<TDEIcon::Group>(
619  config->readNumEntry( TQString("IconGroup_") + number )) );
620 }
621 
622 void KURLBar::writeConfig( TDEConfig *config, const TQString& itemGroup )
623 {
624  TDEConfigGroupSaver cs1( config, itemGroup );
625  if(!config->hasDefault("Speedbar IconSize") && m_iconSize == d->defaultIconSize )
626  config->revertToDefault("Speedbar IconSize");
627  else
628  config->writeEntry( "Speedbar IconSize", m_iconSize );
629 
630  if ( !m_isModified )
631  return;
632 
633  int i = 0;
634  int numLocal = 0;
635  KURLBarItem *item = static_cast<KURLBarItem*>( m_listBox->firstItem() );
636 
637  while ( item )
638  {
639  if ( item->isPersistent() ) // we only save persistent items
640  {
641  if ( item->applicationLocal() )
642  {
643  writeItem( item, numLocal, config, false );
644  numLocal++;
645  }
646 
647  i++;
648  }
649  item = static_cast<KURLBarItem*>( item->next() );
650  }
651  config->writeEntry("Number of Entries", numLocal);
652 
653 
654  // write the global entries to kdeglobals, if any
655  bool haveGlobalEntries = (i > numLocal);
656  if ( m_useGlobal && haveGlobalEntries ) {
657  config->setGroup( itemGroup + " (Global)" );
658 
659  int numGlobals = 0;
660  item = static_cast<KURLBarItem*>( m_listBox->firstItem() );
661 
662  while ( item )
663  {
664  if ( item->isPersistent() ) // we only save persistent items
665  {
666  if ( !item->applicationLocal() )
667  {
668  writeItem( item, numGlobals, config, true );
669  numGlobals++;
670  }
671  }
672 
673  item = static_cast<KURLBarItem*>( item->next() );
674  }
675  config->writeEntry("Number of Entries", numGlobals, true, true);
676  }
677 
678  m_isModified = false;
679 }
680 
681 void KURLBar::writeItem( KURLBarItem *item, int i, TDEConfig *config,
682  bool global )
683 {
684  if ( !item->isPersistent() )
685  return;
686 
687  TQString Description = "Description_";
688  TQString URL = "URL_";
689  TQString Icon = "Icon_";
690  TQString IconGroup = "IconGroup_";
691 
692  TQString number = TQString::number( i );
693  config->writePathEntry( URL + number, item->url().prettyURL(), true, global );
694 
695  config->writeEntry( Description + number, item->description(),true,global);
696  config->writeEntry( Icon + number, item->icon(), true, global );
697  config->writeEntry( IconGroup + number, item->iconGroup(), true, global );
698 }
699 
700 
701 void KURLBar::slotDropped( TQDropEvent *e )
702 {
703  KURL::List urls;
704  if ( KURLDrag::decode( e, urls ) ) {
705  KURL url;
706  TQString description;
707  TQString icon;
708  bool appLocal = false;
709 
710  KURL::List::Iterator it = urls.begin();
711  for ( ; it != urls.end(); ++it ) {
712  (void) insertItem( *it, description, appLocal, icon );
713  m_isModified = true;
714  updateGeometry();
715  }
716  }
717 }
718 
719 void KURLBar::slotContextMenuRequested( TQListBoxItem *_item, const TQPoint& pos )
720 {
721  if (m_isImmutable)
722  return;
723 
724  KURLBarItem *item = dynamic_cast<KURLBarItem*>( _item );
725 
726  static const int IconSize = 10;
727  static const int AddItem = 20;
728  static const int EditItem = 30;
729  static const int RemoveItem = 40;
730 
731  KURL lastURL = m_activeItem ? m_activeItem->url() : KURL();
732 
733  bool smallIcons = m_iconSize < TDEIcon::SizeMedium;
734  TQPopupMenu *popup = new TQPopupMenu();
735  popup->insertItem( smallIcons ?
736  i18n("&Large Icons") : i18n("&Small Icons"),
737  IconSize );
738  popup->insertSeparator();
739 
740  if (item != 0L && item->isPersistent())
741  {
742  popup->insertItem(SmallIconSet("edit"), i18n("&Edit Entry..."), EditItem);
743  popup->insertSeparator();
744  }
745 
746  popup->insertItem(SmallIconSet("document-new"), i18n("&Add Entry..."), AddItem);
747 
748  if (item != 0L && item->isPersistent())
749  {
750  popup->insertItem( SmallIconSet("edit-delete"), i18n("&Remove Entry"),
751  RemoveItem );
752  }
753 
754  int result = popup->exec( pos );
755  switch ( result ) {
756  case IconSize:
757  setIconSize( smallIcons ? TDEIcon::SizeMedium : TDEIcon::SizeSmallMedium );
758  m_listBox->triggerUpdate( true );
759  break;
760  case AddItem:
761  addNewItem();
762  break;
763  case EditItem:
764  editItem( static_cast<KURLBarItem *>( item ) );
765  break;
766  case RemoveItem:
767  delete item;
768  m_isModified = true;
769  break;
770  default: // abort
771  break;
772  }
773 
774  // reset current item
775  m_activeItem = 0L;
776  setCurrentItem( lastURL );
777 }
778 
779 bool KURLBar::addNewItem()
780 {
781  KURLBarItem *item = new KURLBarItem( this, d->currentURL,
782  i18n("Enter a description") );
783  if ( editItem( item ) ) {
784  m_listBox->insertItem( item );
785  return true;
786  }
787 
788  delete item;
789  return false;
790 }
791 
792 bool KURLBar::editItem( KURLBarItem *item )
793 {
794  if ( !item || !item->isPersistent() ) // should never happen tho
795  return false;
796 
797  KURL url = item->url();
798  TQString description = item->description();
799  TQString icon = item->icon();
800  bool appLocal = item->applicationLocal();
801 
802  if ( KURLBarItemDialog::getInformation( m_useGlobal,
803  url, description,
804  icon, appLocal,
805  m_iconSize, this ))
806  {
807  item->setURL( url );
808  item->setDescription( description );
809  item->setIcon( icon );
810  item->setApplicationLocal( appLocal );
811  m_listBox->triggerUpdate( true );
812  m_isModified = true;
813  updateGeometry();
814  return true;
815  }
816 
817  return false;
818 }
819 
822 
823 
824 KURLBarListBox::KURLBarListBox( TQWidget *parent, const char *name )
825  : TDEListBox( parent, name )
826 {
827  m_toolTip = new KURLBarToolTip( this );
828  setAcceptDrops( true );
829  viewport()->setAcceptDrops( true );
830 }
831 
832 KURLBarListBox::~KURLBarListBox()
833 {
834  delete m_toolTip;
835 }
836 
837 void KURLBarListBox::paintEvent( TQPaintEvent* )
838 {
839  TQPainter p(this);
840  p.setPen( colorGroup().mid() );
841  p.drawRect( 0, 0, width(), height() );
842 }
843 
844 TQDragObject * KURLBarListBox::dragObject()
845 {
846  KURL::List urls;
847  KURLBarItem *item = static_cast<KURLBarItem*>( firstItem() );
848 
849  while ( item ) {
850  if ( item->isSelected() )
851  urls.append( item->url() );
852  item = static_cast<KURLBarItem*>( item->next() );
853  }
854 
855  if ( !urls.isEmpty() ) // ### use custom drag-object with description etc.?
856  return new KURLDrag( urls, this, "urlbar drag" );
857 
858  return 0L;
859 }
860 
861 void KURLBarListBox::contentsDragEnterEvent( TQDragEnterEvent *e )
862 {
863  e->accept( KURLDrag::canDecode( e ));
864 }
865 
866 void KURLBarListBox::contentsDropEvent( TQDropEvent *e )
867 {
868  emit dropped( e );
869 }
870 
871 void KURLBarListBox::contextMenuEvent( TQContextMenuEvent *e )
872 {
873  if (e)
874  {
875  emit contextMenuRequested( itemAt( e->globalPos() ), e->globalPos() );
876  e->consume(); // Consume the event to avoid multiple contextMenuEvent calls...
877  }
878 }
879 
880 void KURLBarListBox::setOrientation( TQt::Orientation orient )
881 {
882  if ( orient == TQt::Vertical ) {
883  setColumnMode( 1 );
884  setRowMode( Variable );
885  }
886  else {
887  setRowMode( 1 );
888  setColumnMode( Variable );
889  }
890 
891  m_orientation = orient;
892 }
893 
896 
897 
898 bool KURLBarItemDialog::getInformation( bool allowGlobal, KURL& url,
899  TQString& description, TQString& icon,
900  bool& appLocal, int iconSize,
901  TQWidget *parent )
902 {
903  KURLBarItemDialog *dialog = new KURLBarItemDialog( allowGlobal, url,
904  description, icon,
905  appLocal,
906  iconSize, parent );
907  if ( dialog->exec() == TQDialog::Accepted ) {
908  // set the return parameters
909  url = dialog->url();
910  description = dialog->description();
911  icon = dialog->icon();
912  appLocal = dialog->applicationLocal();
913 
914  delete dialog;
915  return true;
916  }
917 
918  delete dialog;
919  return false;
920 }
921 
922 KURLBarItemDialog::KURLBarItemDialog( bool allowGlobal, const KURL& url,
923  const TQString& description,
924  TQString icon, bool appLocal,
925  int iconSize,
926  TQWidget *parent, const char *name )
927  : KDialogBase( parent, name, true,
928  i18n("Edit Quick Access Entry"), Ok | Cancel, Ok, true )
929 {
930  TQVBox *box = new TQVBox( this );
931  TQString text = i18n("<qt><b>Please provide a description, URL and icon for this Quick Access entry.</b></br></qt>");
932  TQLabel *label = new TQLabel( text, box );
933  box->setSpacing( spacingHint() );
934 
935  TQGrid *grid = new TQGrid( 2, box );
936  grid->setSpacing( spacingHint() );
937 
938  TQString whatsThisText = i18n("<qt>This is the text that will appear in the Quick Access panel.<p>"
939  "The description should consist of one or two words "
940  "that will help you remember what this entry refers to.</qt>");
941  label = new TQLabel( i18n("&Description:"), grid );
942  m_edit = new KLineEdit( grid, "description edit" );
943  m_edit->setText( description.isEmpty() ? url.fileName() : description );
944  label->setBuddy( m_edit );
945  TQWhatsThis::add( label, whatsThisText );
946  TQWhatsThis::add( m_edit, whatsThisText );
947 
948  whatsThisText = i18n("<qt>This is the location associated with the entry. Any valid URL may be used. For example:<p>"
949  "%1<br>http://www.trinitydesktop.org<p>"
950  "By clicking on the button next to the text edit box you can browse to an "
951  "appropriate URL.</qt>").arg(TQDir::homeDirPath());
952  label = new TQLabel( i18n("&URL:"), grid );
953  m_urlEdit = new KURLRequester( url.prettyURL(), grid );
954  m_urlEdit->setMode( KFile::Directory );
955  label->setBuddy( m_urlEdit );
956  TQWhatsThis::add( label, whatsThisText );
957  TQWhatsThis::add( m_urlEdit, whatsThisText );
958 
959  whatsThisText = i18n("<qt>This is the icon that will appear in the Quick Access panel.<p>"
960  "Click on the button to select a different icon.</qt>");
961  label = new TQLabel( i18n("Choose an &icon:"), grid );
962  m_iconButton = new TDEIconButton( grid, "icon button" );
963  m_iconButton->setIconSize( iconSize );
964  if ( icon.isEmpty() )
965  icon = KMimeType::iconForURL( url );
966  m_iconButton->setIcon( icon );
967  label->setBuddy( m_iconButton );
968  TQWhatsThis::add( label, whatsThisText );
969  TQWhatsThis::add( m_iconButton, whatsThisText );
970 
971  if ( allowGlobal ) {
972  TQString appName;
973  if ( TDEGlobal::instance()->aboutData() )
974  appName = TDEGlobal::instance()->aboutData()->programName();
975  if ( appName.isEmpty() )
976  appName = TQString::fromLatin1( TDEGlobal::instance()->instanceName() );
977  m_appLocal = new TQCheckBox( i18n("&Only show when using this application (%1)").arg( appName ), box );
978  m_appLocal->setChecked( appLocal );
979  TQWhatsThis::add( m_appLocal,
980  i18n("<qt>Select this setting if you want this "
981  "entry to show only when using the current application (%1).<p>"
982  "If this setting is not selected, the entry will be available in all "
983  "applications.</qt>")
984  .arg(appName));
985  }
986  else
987  m_appLocal = 0L;
988  connect(m_urlEdit->lineEdit(),TQ_SIGNAL(textChanged ( const TQString & )),this,TQ_SLOT(urlChanged(const TQString & )));
989  m_edit->setFocus();
990  setMainWidget( box );
991 }
992 
993 KURLBarItemDialog::~KURLBarItemDialog()
994 {
995 }
996 
997 void KURLBarItemDialog::urlChanged(const TQString & text )
998 {
999  enableButtonOK( !text.isEmpty() );
1000 }
1001 
1002 KURL KURLBarItemDialog::url() const
1003 {
1004  TQString text = m_urlEdit->url();
1005  KURL u;
1006  if ( text.at(0) == '/' )
1007  u.setPath( text );
1008  else
1009  u = text;
1010 
1011  return u;
1012 }
1013 
1014 TQString KURLBarItemDialog::description() const
1015 {
1016  return m_edit->text();
1017 }
1018 
1019 TQString KURLBarItemDialog::icon() const
1020 {
1021  return m_iconButton->icon();
1022 }
1023 
1024 bool KURLBarItemDialog::applicationLocal() const
1025 {
1026  if ( !m_appLocal )
1027  return true;
1028 
1029  return m_appLocal->isChecked();
1030 }
1031 
1032 void KURLBarItem::virtual_hook( int, void* )
1033 { /*BASE::virtual_hook( id, data );*/ }
1034 
1035 void KURLBar::virtual_hook( int, void* )
1036 { /*BASE::virtual_hook( id, data );*/ }
1037 
1038 void KURLBarListBox::virtual_hook( int id, void* data )
1039 { TDEListBox::virtual_hook( id, data ); }
1040 
1041 
1042 #include "kurlbar.moc"
KURLBarItemDialog
A dialog that allows editing entries of a KURLBar ( KURLBarItem).
Definition: kurlbar.h:568
KURLBarItemDialog::applicationLocal
bool applicationLocal() const
Definition: kurlbar.cpp:1024
KURLBarItemDialog::~KURLBarItemDialog
~KURLBarItemDialog()
Destroys the dialog.
Definition: kurlbar.cpp:993
KURLBarItemDialog::m_iconButton
TDEIconButton * m_iconButton
The TDEIconButton to configure the icon.
Definition: kurlbar.h:645
KURLBarItemDialog::getInformation
static bool getInformation(bool allowGlobal, KURL &url, TQString &description, TQString &icon, bool &appLocal, int iconSize, TQWidget *parent=0)
A convenience method to show the dialog and retrieve all the properties via the given parameters.
Definition: kurlbar.cpp:898
KURLBarItemDialog::url
KURL url() const
Definition: kurlbar.cpp:1002
KURLBarItemDialog::KURLBarItemDialog
KURLBarItemDialog(bool allowGlobal, const KURL &url, const TQString &description, TQString icon, bool appLocal=true, int iconSize=TDEIcon::SizeMedium, TQWidget *parent=0, const char *name=0)
Constructs a KURLBarItemDialog.
Definition: kurlbar.cpp:922
KURLBarItemDialog::m_urlEdit
KURLRequester * m_urlEdit
The KURLRequester used for editing the url.
Definition: kurlbar.h:637
KURLBarItemDialog::description
TQString description() const
Definition: kurlbar.cpp:1014
KURLBarItemDialog::icon
TQString icon() const
Definition: kurlbar.cpp:1019
KURLBarItemDialog::m_edit
KLineEdit * m_edit
The KLineEdit used for editing the description.
Definition: kurlbar.h:641
KURLBarItemDialog::m_appLocal
TQCheckBox * m_appLocal
The TQCheckBox to modify the local/global setting.
Definition: kurlbar.h:649
KURLBarItem
An item to be used in KURLBar / KURLBarListBox.
Definition: kurlbar.h:43
KURLBarItem::setDescription
void setDescription(const TQString &desc)
Sets the description of this item that will be shown as item-text.
Definition: kurlbar.cpp:149
KURLBarItem::setIcon
void setIcon(const TQString &icon, TDEIcon::Group group=TDEIcon::Panel)
sets the icon for this item.
Definition: kurlbar.cpp:137
KURLBarItem::iconGroup
TDEIcon::Group iconGroup() const
returns the icon-group of this item (determines icon-effects).
Definition: kurlbar.h:147
KURLBarItem::applicationLocal
bool applicationLocal() const
returns whether this is a global item or a local one.
Definition: kurlbar.h:167
KURLBarItem::pixmap
virtual const TQPixmap * pixmap() const
returns the pixmap of this item.
Definition: kurlbar.h:151
KURLBarItem::toolTip
TQString toolTip() const
returns the tooltip of this item.
Definition: kurlbar.cpp:171
KURLBarItem::setToolTip
void setToolTip(const TQString &tip)
Sets a tooltip to be used for this item.
Definition: kurlbar.cpp:166
KURLBarItem::width
virtual int width(const TQListBox *) const
returns the width of this item.
Definition: kurlbar.cpp:296
KURLBarItem::setApplicationLocal
void setApplicationLocal(bool local)
Makes this item a local or global one.
Definition: kurlbar.cpp:155
KURLBarItem::url
const KURL & url() const
returns the url of this item.
Definition: kurlbar.h:127
KURLBarItem::setURL
void setURL(const KURL &url)
Sets url for this item.
Definition: kurlbar.cpp:130
KURLBarItem::description
const TQString & description() const
returns the description of this item.
Definition: kurlbar.h:132
KURLBarItem::KURLBarItem
KURLBarItem(KURLBar *parent, const KURL &url, bool persistent, const TQString &description=TQString::null, const TQString &icon=TQString::null, TDEIcon::Group group=TDEIcon::Panel)
Creates a KURLBarItem to be used in the parent KURLBar.
Definition: kurlbar.cpp:90
KURLBarItem::height
virtual int height(const TQListBox *) const
returns the height of this item.
Definition: kurlbar.cpp:304
KURLBarItem::sizeHint
TQSize sizeHint() const
returns the preferred size of this item
Definition: kurlbar.cpp:273
KURLBarItem::isPersistent
bool isPersistent() const
returns whether this item is persistent (via KURLBar::writeConfig() and KURLBar::readConfig()) or not...
Definition: kurlbar.cpp:312
KURLBarItem::~KURLBarItem
~KURLBarItem()
Destroys the item.
Definition: kurlbar.cpp:125
KURLBarItem::icon
const TQString & icon() const
returns the icon of this item.
Definition: kurlbar.h:137
KURLBarListBox
This is the listbox used in KURLBar.
Definition: kurlbar.h:494
KURLBarListBox::dropped
void dropped(TQDropEvent *e)
Emitted when a drop-event happened.
KURLBarListBox::orientation
TQt::Orientation orientation() const
Definition: kurlbar.h:518
KURLBarListBox::dragObject
virtual TQDragObject * dragObject()
Definition: kurlbar.cpp:844
KURLBarListBox::KURLBarListBox
KURLBarListBox(TQWidget *parent=0, const char *name=0)
Constructs a KURLBarListBox.
Definition: kurlbar.cpp:824
KURLBarListBox::~KURLBarListBox
~KURLBarListBox()
Destroys the box.
Definition: kurlbar.cpp:832
KURLBarListBox::setOrientation
virtual void setOrientation(TQt::Orientation orient)
Sets the orientation of the widget.
Definition: kurlbar.cpp:880
KURLBar
KURLBar is a widget that displays icons together with a description.
Definition: kurlbar.h:231
KURLBar::activated
void activated(const KURL &url)
This signal is emitted when the user activated an item, e.g., by clicking on it.
KURLBar::m_useGlobal
bool m_useGlobal
Whether we support global entries or just local ones.
Definition: kurlbar.h:430
KURLBar::currentItem
KURLBarItem * currentItem() const
Definition: kurlbar.cpp:568
KURLBar::clear
virtual void clear()
Clears the view, removes all items.
Definition: kurlbar.cpp:444
KURLBar::isVertical
bool isVertical() const
Definition: kurlbar.h:385
KURLBar::setListBox
virtual void setListBox(KURLBarListBox *)
Allows to set a custom KURLBarListBox.
Definition: kurlbar.cpp:396
KURLBar::addNewItem
virtual bool addNewItem()
Pops up a KURLBarItemDialog to let the user add a new item.
Definition: kurlbar.cpp:779
KURLBar::readConfig
virtual void readConfig(TDEConfig *config, const TQString &itemGroup)
Call this method to read a saved configuration from config, inside the group itemGroup.
Definition: kurlbar.cpp:582
KURLBar::writeItem
virtual void writeItem(KURLBarItem *item, int i, TDEConfig *, bool global)
Called from writeConfig() to save the KURLBarItem item as the i'th entry in the config-object.
Definition: kurlbar.cpp:681
KURLBar::setCurrentItem
virtual void setCurrentItem(const KURL &url)
Makes the item with the url url the current item.
Definition: kurlbar.cpp:540
KURLBar::iconSize
int iconSize() const
Definition: kurlbar.h:311
KURLBar::KURLBar
KURLBar(bool useGlobalItems, TQWidget *parent=0, const char *name=0, WFlags f=0)
Constructs a KURLBar.
Definition: kurlbar.cpp:334
KURLBar::insertDynamicItem
virtual KURLBarItem * insertDynamicItem(const KURL &url, const TQString &description, const TQString &icon=TQString::null, TDEIcon::Group group=TDEIcon::Panel)
Inserts a new dynamic item into the KURLBar and returns the created KURLBarItem.
Definition: kurlbar.cpp:372
KURLBar::slotContextMenuRequested
virtual void slotContextMenuRequested(TQListBoxItem *, const TQPoint &pos)
Reimplemented to show a contextmenu, allowing the user to add, edit or remove items,...
Definition: kurlbar.cpp:719
KURLBar::setOrientation
virtual void setOrientation(TQt::Orientation orient)
The items can be arranged either vertically in one column or horizontally in one row.
Definition: kurlbar.cpp:380
KURLBar::readItem
virtual void readItem(int i, TDEConfig *config, bool applicationLocal)
Called from readConfig() to read the i'th from config.
Definition: kurlbar.cpp:605
KURLBar::editItem
virtual bool editItem(KURLBarItem *item)
Pops up a KURLBarItemDialog to let the user edit the properties of item.
Definition: kurlbar.cpp:792
KURLBar::setIconSize
virtual void setIconSize(int size)
Sets the default iconsize to be used for items inserted with insertItem.
Definition: kurlbar.cpp:426
KURLBar::currentURL
KURL currentURL() const
Definition: kurlbar.cpp:576
KURLBar::m_isModified
bool m_isModified
Whether the urlbar was modified by the user (e.g.
Definition: kurlbar.h:436
KURLBar::writeConfig
virtual void writeConfig(TDEConfig *config, const TQString &itemGroup)
Call this method to save the current configuration into config, inside the group iconGroup.
Definition: kurlbar.cpp:622
KURLBar::m_activeItem
KURLBarItem * m_activeItem
The currently active item.
Definition: kurlbar.h:426
KURLBar::~KURLBar
~KURLBar()
Destroys the KURLBar.
Definition: kurlbar.cpp:357
KURLBar::sizeHint
virtual TQSize sizeHint() const
Definition: kurlbar.cpp:471
KURLBar::insertItem
virtual KURLBarItem * insertItem(const KURL &url, const TQString &description, bool applicationLocal=true, const TQString &icon=TQString::null, TDEIcon::Group group=TDEIcon::Panel)
Inserts a new item into the KURLBar and returns the created KURLBarItem.
Definition: kurlbar.cpp:362
KURLBar::orientation
Orientation orientation() const
Definition: kurlbar.cpp:391
KURLBar::m_isImmutable
bool m_isImmutable
Whether the urlbar may be modified by the user.
Definition: kurlbar.h:442
KURLBar::slotDropped
virtual void slotDropped(TQDropEvent *)
Called when a url was dropped onto the bar to show a KURLBarItemDialog.
Definition: kurlbar.cpp:701
KURLBar::minimumSizeHint
virtual TQSize minimumSizeHint() const
Definition: kurlbar.cpp:513
KURLBar::slotSelected
virtual void slotSelected(TQListBoxItem *)
Called when an item has been selected.
Definition: kurlbar.cpp:529
KURLRequester
This class is a widget showing a lineedit and a button, which invokes a filedialog.
Definition: kurlrequester.h:57
KURLRequester::setMode
void setMode(uint m)
Sets the mode of the file dialog.
Definition: kurlrequester.cpp:311
KURLRequester::url
TQString url() const
Definition: kurlrequester.cpp:268
KURLRequester::lineEdit
KLineEdit * lineEdit() const
Definition: kurlrequester.cpp:369
TDEIconButton
A pushbutton for choosing an icon.
Definition: kicondialog.h:258
TDEIconButton::icon
TQString icon() const
Returns the name of the selected icon.
Definition: kicondialog.h:309
TDEIconButton::setIconSize
void setIconSize(int size)
Sets the size of the icon to be shown / selected.
Definition: kicondialog.cpp:700
TDEIconButton::setIcon
void setIcon(const TQString &icon)
Sets the button's initial icon.
Definition: kicondialog.cpp:717

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdefile by doxygen 1.9.1
This website is maintained by Timothy Pearson.