Source Code (Use browser search to find items of interest.)

Class Index

kdesktop'KDesktop (./kdebase/kdesktop/desktop.h:42)

class KDesktop : public KonqIconViewWidget, virtual public KDesktopIface
{
  Q_OBJECT
public:

  KDesktop(const QString& _url, bool x_root_hack, bool auto_start);
  ~KDesktop();


  /**
   * Re-arrange the desktop icons
   * @param bAsk if true a confirmation is asked first
   */
  virtual void rearrangeIcons( int bAsk );
  /**
   * Select icons in the rectangle given
   */
  virtual void selectIconsInRect( int /*x*/, int /*y*/, int /*dx*/, int /*dy*/ )
   {/* selectByRubber( QRect(x, y, dx, dy) ); */ }
  /**
   * Select all icons
   */
  virtual void selectAll() { QIconView::selectAll( true ); }
  /**
   * Unselect all icons
   */
  virtual void unselectAll()  { QIconView::selectAll( false ); }
  /**
   * @return the urls of selected icons
   */
  virtual QStringList selectedURLs();
  /**
   * Re-read KDesktop's configuration
   */
  virtual void configure();
  /**
   * Display the "Execute Command" dialog (min-cli)
   */
  virtual void popupExecuteCommand();

  virtual void setMoveSelection( int b ) { s_bMoveSelection = (bool) b; }


  KWinModule* kwinModule() const { return m_pKwinmodule; }

protected slots:
  /**
   * Activate the desktop.
   */
  void slotStart();

  void slotExecuteCommand();

  /**
   * Connected to KSycoca
   */
  virtual void slotDatabaseChanged();

  // slots connected to the icon view
  void slotReturnPressed( QIconViewItem *item );
  void slotMouseButtonPressed(int, QIconViewItem*, const QPoint&);
  void slotEnableAction( const char * name, bool enabled );

  void slotItemRenamed(QIconViewItem*);

  // slots connected to the directory lister
  void slotClear();
  void slotCompleted();
  void slotNewItems( const KonqFileItemList& );
  void slotDeleteItem( KonqFileItem * );

  // slots connected to the popupmenu (actions)
  void slotCut();
  void slotCopy();
  void slotTrash();
  void slotDelete();
  void slotShred();

public slots: // for krootwm

  void slotPaste();

protected:
  virtual void initConfig();
  virtual void popupMenu( const QPoint &_global, KFileItemList _items );
  virtual void showEvent( QShowEvent *e );
  virtual void closeEvent( QCloseEvent * );

  /**
   * Set to true while the constructor is running.
   * @ref #initConfig needs to know about that.
   */
  bool m_bInit;

  /** Show dot files ? */
  bool m_bShowDot;

  /** Execute files from autoexec folder? */
  bool m_bAutoStart;

  /** Vertical or Horizontal align of icons on desktop */
  bool m_bVertAlign;
  QIconView::Arrangement m_tAlign;

  /** Settings - see libkonq/konqsettings.* */
  KonqSettings* m_pSettings;

  /** The directory lister for this URL */
  KDirLister* m_dirLister;

  KGlobalAccel *m_keys;

  KActionCollection m_actionCollection;

  static bool s_bMoveSelection;

  KWinModule* m_pKwinmodule;

  /** Initial plash screen */
  QFrame *splash;

  KDesktopFile *m_dotDirectory;
};

kdesktop'KDesktop::KDesktop() (./kdebase/kdesktop/desktop.cc:76)

KDesktop::KDesktop( const QString& _url, bool x_root_hack, bool auto_start ) :
    KonqIconViewWidget( 0L, "desktop", x_root_hack ? WStyle_Customize | WStyle_NoBorder : 0 ),
    DCOPObject( "KDesktopIface" )
{
  m_bAutoStart = auto_start;
  KGlobal::locale()->insertCatalogue("kdesktop");
  KGlobal::locale()->insertCatalogue("libkonq"); // needed for apps using libkonq

  setCaption( "THE DESKTOP"); // kwin will understand that for now

  setFrameStyle(NoFrame);
  // we don't want a scrolling desktop
  setVScrollBarMode( AlwaysOff );
  setHScrollBarMode( AlwaysOff );
  setDragAutoScroll( false );
  m_pKwinmodule = new KWinModule( this );

  KURL url( _url );
  assert( !url.isMalformed() );
  setURL( url );

  // Dont repaint on configuration changes during construction
  m_bInit = true;

  setFocusPolicy( StrongFocus );
  viewport()->setFocusPolicy( StrongFocus );

  if ( x_root_hack )
  {
    // this is a ugly hack to make Dnd work
    // Matthias told me that it won't be necessary with kwin
    // actually my first try with ICCCM (Dirk) :-)
    unsigned long data[2];
    data[0] = (unsigned long) 1;
    data[1] = (unsigned long) None;
    Atom wm_state = XInternAtom(qt_xdisplay(), "WM_STATE", False);
    XChangeProperty(qt_xdisplay(), winId(), wm_state, wm_state, 32,
                    PropModeReplace, (unsigned char *)data, 2);

    QRect area = KWM::windowRegion(KWM::currentDesktop());
    setGeometry( area );
  }
  else
    setGeometry( QApplication::desktop()->geometry() );

  // Geert Jansen: backgroundmanager belongs here
  new KBackgroundManager(viewport(), m_pKwinmodule );

  lower();
  show();

  {
     splash = new QFrame(0, "intro_splash",
	WStyle_Customize | WStyle_StaysOnTop | WStyle_NoBorder
			 | WDestructiveClose );
     splash->setFrameStyle( QFrame::Box | QFrame::Raised );
     splash->setLineWidth(2);
     KWM::setDecoration( splash->winId(), KWM::noDecoration );
//     QPixmap pm( locate("appdata", "pics/kdeintro.png"));
     QPixmap pm( locate("data", "kwelcome/pics/welcome.png"));
     splash->setBackgroundPixmap(pm);
     int x = (QApplication::desktop()->width()- pm.width())/2;
     int y = (QApplication::desktop()->height()- pm.height())/2;
     splash->move(x,y);
     splash->setFixedSize( pm.size());
     splash->show();
     QTimer::singleShot( 4000, splash, SLOT( close() ) );
  }

  connect( this, SIGNAL( executed( QIconViewItem * ) ),
           SLOT( slotReturnPressed( QIconViewItem * ) ) );
  connect( this, SIGNAL( returnPressed( QIconViewItem * ) ),
           SLOT( slotReturnPressed( QIconViewItem * ) ) );
  connect( this, SIGNAL( enableAction( const char * , bool ) ),
           SLOT( slotEnableAction( const char * , bool ) ) );

  connect( this, SIGNAL( mouseButtonPressed(int, QIconViewItem*, const QPoint&)),
           SLOT( slotMouseButtonPressed(int, QIconViewItem*, const QPoint&)) );
  connect( this, SIGNAL(itemRenamed(QIconViewItem*)),
           SLOT( slotItemRenamed(QIconViewItem*)) );
  connect( this, SIGNAL( dropped() ),
	   this, SLOT( slotSaveIconPositions() ) );

  connect(KSycoca::self(), SIGNAL(databaseChanged()), this, SLOT(slotDatabaseChanged()));

  QTimer::singleShot(2000, this, SLOT( slotStart()));

  m_dotDirectory = 0;
}

void

kdesktop'KDesktop::slotStart() (./kdebase/kdesktop/desktop.cc:167)

KDesktop::slotStart()
{
  if (!m_bInit) return;

  initConfig();

  // Now we may react to configuration changes
  m_bInit = false;

  // Create the directory lister
  m_dirLister = new KDirLister();

  connect( m_dirLister, SIGNAL( clear() ), this, SLOT( slotClear() ) );
  connect( m_dirLister, SIGNAL( completed() ), this, SLOT( slotCompleted() ) );
  connect( m_dirLister, SIGNAL( newItems( const KonqFileItemList & ) ),
           this, SLOT( slotNewItems( const KonqFileItemList & ) ) );
  connect( m_dirLister, SIGNAL( deleteItem( KonqFileItem * ) ),
           this, SLOT( slotDeleteItem( KonqFileItem * ) ) );

  // Start the directory lister !
  m_dirLister->openURL( m_url, m_bShowDot );

  setIcons( 0 ); // to be made configurable ?
  setResizeMode( Fixed );

    // Global keys
  m_keys = new KGlobalAccel;
  m_keys->insertItem(i18n("Execute command"),  "Execute command", "ALT+F2");
  m_keys->connectItem("Execute command", this, SLOT(slotExecuteCommand()));

  m_keys->readSettings();

  (void) new KAction( i18n( "&Cut" ), "editcut", KStdAccel::key(KStdAccel::Cut), this, SLOT( slotCut() ), &m_actionCollection, "cut" );
  (void) new KAction( i18n( "&Copy" ), "editcopy", KStdAccel::key(KStdAccel::Copy), this, SLOT( slotCopy() ), &m_actionCollection, "copy" );
  (void) new KAction( i18n( "&Paste" ), "editpaste", KStdAccel::key(KStdAccel::Paste), this, SLOT( slotPaste() ), &m_actionCollection, "paste" );

  KConfig config("konquerorrc", false, true); // This is set in konquerorrc...
  config.setGroup( "Trash" );
  int deleteAction = config.readNumEntry("DeleteAction", DEFAULT_DELETEACTION);
  const int deleteKey = CTRL+Key_Delete ; // Key_Delete conflict with the location bar
  (void) new KAction( i18n( "&Move to Trash" ), "trash", deleteAction==1 ? deleteKey : 0, this, SLOT( slotTrash() ), &m_actionCollection, "trash" );
  (void) new KAction( i18n( "&Delete" ), deleteAction==2 ? deleteKey : 0, this, SLOT( slotDelete() ), &m_actionCollection, "del" );
  (void) new KAction( i18n( "&Shred" ), deleteAction==3 ? deleteKey : 0, this, SLOT( slotShred() ), &m_actionCollection, "shred" );

  new KRootWm( this ); // handler for root menu (used by kdesktop on RMB click)

  if ( m_bAutoStart )
  {
     // now let's execute all the stuff in the autostart folder.
     // the stuff will actually be really executed when the event loop is
     // entered, since KRun internally uses a QTimer
     QDir dir( KGlobalSettings::autostartPath() );
     QStringList entries = dir.entryList( QDir::Files );
     QStringList::Iterator it = entries.begin();
     QStringList::Iterator end = entries.end();
     for (; it != end; ++it )
     {
            // Don't execute backup files
            if ( (*it).right(1) != "~" && (*it).right(4) != ".bak" &&
                 ( (*it)[0] != '%' || (*it).right(1) != "%" ) &&
                 ( (*it)[0] != '#' || (*it).right(1) != "#" ) )
                (void) new KRun( (*it).prepend( QString::fromLatin1( "file:" ) + dir.absPath() + '/' ), 0, true );
     }
   }

  m_dotDirectory = new KDesktopFile( m_dotDirectoryPath, true );
}

// -----------------------------------------------------------------------------


kdesktop'KDesktop::~KDesktop() (./kdebase/kdesktop/desktop.cc:237)

KDesktop::~KDesktop()
{
  delete m_dirLister;
}

// -----------------------------------------------------------------------------


kdesktop'KDesktop::initConfig() (./kdebase/kdesktop/desktop.cc:244)

void KDesktop::initConfig()
{
  KConfig * config = KGlobal::config();
  config->setGroup( "Desktop Icons" );
  m_bShowDot = config->readBoolEntry("ShowHidden", DEFAULT_SHOW_HIDDEN_ROOT_ICONS);
  m_bVertAlign = config->readBoolEntry("VertAlign", DEFAULT_VERT_ALIGN);
  if ( !m_bInit ) { // only when called while running - not on first startup
    m_dirLister->setShowingDotFiles( m_bShowDot );
    m_keys->readSettings();
  }
  m_tAlign = m_bVertAlign ? TopToBottom : LeftToRight;
  setArrangement(m_tAlign);

  KonqIconViewWidget::initConfig();

  setAutoArrange( false );
}

// -----------------------------------------------------------------------------


kdesktop'KDesktop::slotExecuteCommand() (./kdebase/kdesktop/desktop.cc:264)

void KDesktop::slotExecuteCommand()
{
    // this function needs to be duplicated since it appears that one
    // cannot have a 'slot' be a DCOP method.  if this changes in the
    // future, then 'slotExecuteCommand' and 'popupExecuteCommand' can
    // merge into one slot.
    popupExecuteCommand();
}

// -----------------------------------------------------------------------------


kdesktop'KDesktop::popupExecuteCommand() (./kdebase/kdesktop/desktop.cc:275)

void KDesktop::popupExecuteCommand()
{
    if (m_bInit) return;
    KRootWm::getRootWm()->executeCommand();
}

// -----------------------------------------------------------------------------


kdesktop'KDesktop::rearrangeIcons() (./kdebase/kdesktop/desktop.cc:283)

void KDesktop::rearrangeIcons( int bAsk )
{
  if ( (bool)bAsk )
    if ( KMessageBox::questionYesNo( 0L,
         i18n( "Do you really want to rearrange your icons?" )) == KMessageBox::No )
      return;

  arrangeItemsInGrid();
  slotSaveIconPositions();
}


// -----------------------------------------------------------------------------


kdesktop'KDesktop::selectedURLs() (./kdebase/kdesktop/desktop.cc:297)

QStringList KDesktop::selectedURLs()
{
    QStringList seq;

    QIconViewItem *it = firstItem();
    for (; it; it = it->nextItem() )
        if ( it->isSelected() ) {
            KFileItem *fItem = ((KFileIVI *)it)->item();
            seq.append( fItem->url().url() ); // copy the URL
        }

    return seq;
}

// -----------------------------------------------------------------------------


kdesktop'KDesktop::configure() (./kdebase/kdesktop/desktop.cc:313)

void KDesktop::configure()
{
    // re-read configuration and apply it
    KGlobal::config()->reparseConfiguration();
    KonqFMSettings::reparseConfiguration();
    if (!m_bInit)
    {
       initConfig();
       KRootWm::getRootWm()->initConfig();
    }
}


// -----------------------------------------------------------------------------

kdesktop'KDesktop::slotDatabaseChanged() (./kdebase/kdesktop/desktop.cc:327)

void KDesktop::slotDatabaseChanged()
{
  if (m_bInit)
     slotStart();
  refreshMimeTypes();
}

// -----------------------------------------------------------------------------


kdesktop'KDesktop::slotMouseButtonPressed() (./kdebase/kdesktop/desktop.cc:336)

void KDesktop::slotMouseButtonPressed(int _button, QIconViewItem* _item, const QPoint& _global)
{
    if (m_bInit) return;
    if(_item) {
        switch(_button) {
        case RightButton:
            ((KFileIVI*)_item)->setSelected( true );
            popupMenu( _global, selectedFileItems() );
            break;
        case MidButton:
            slotReturnPressed( _item );
            break;
        }
    }
    else
    {
        KRootWm::getRootWm()->mousePressed( _global, _button );
    }
}


// -----------------------------------------------------------------------------


kdesktop'KDesktop::slotReturnPressed() (./kdebase/kdesktop/desktop.cc:359)

void KDesktop::slotReturnPressed( QIconViewItem *item )
{
  kapp->propagateSessionManager();
  if (item)
    ((KFileIVI*)item)->returnPressed();
}

// -----------------------------------------------------------------------------


kdesktop'KDesktop::slotCut() (./kdebase/kdesktop/desktop.cc:368)

void KDesktop::slotCut()
{
  cutSelection();

  QByteArray data;
  QDataStream stream( data, IO_WriteOnly );
  stream << (int)true;
  kapp->dcopClient()->send( "konqueror*", "KonquerorIface", "setMoveSelection(int)", data );
  kapp->dcopClient()->send( "kdesktop", "KDesktopIface", "setMoveSelection(int)", data );
  s_bMoveSelection = true;
}

// -----------------------------------------------------------------------------


kdesktop'KDesktop::slotCopy() (./kdebase/kdesktop/desktop.cc:382)

void KDesktop::slotCopy()
{
  copySelection();

  QByteArray data;
  QDataStream stream( data, IO_WriteOnly );
  stream << (int)false;
  kapp->dcopClient()->send( "konqueror*", "KonquerorIface", "setMoveSelection(int)", data );
  kapp->dcopClient()->send( "kdesktop", "KDesktopIface", "setMoveSelection(int)", data );
  s_bMoveSelection = false;
}

// -----------------------------------------------------------------------------


kdesktop'KDesktop::slotPaste() (./kdebase/kdesktop/desktop.cc:396)

void KDesktop::slotPaste()
{
  pasteSelection( s_bMoveSelection );
}


kdesktop'KDesktop::slotTrash() (./kdebase/kdesktop/desktop.cc:401)

void KDesktop::slotTrash()
{
  KonqOperations::del(this, KonqOperations::TRASH, selectedUrls());
}


kdesktop'KDesktop::slotDelete() (./kdebase/kdesktop/desktop.cc:406)

void KDesktop::slotDelete()
{
  KonqOperations::del(this, KonqOperations::DEL, selectedUrls());
}


kdesktop'KDesktop::slotShred() (./kdebase/kdesktop/desktop.cc:411)

void KDesktop::slotShred()
{
  KonqOperations::del(this, KonqOperations::SHRED, selectedUrls());
}

// -----------------------------------------------------------------------------


kdesktop'KDesktop::popupMenu() (./kdebase/kdesktop/desktop.cc:418)

void KDesktop::popupMenu( const QPoint &_global, KFileItemList _items )
{
   if (m_bInit) return;
   KonqPopupMenu * popupMenu = new KonqPopupMenu( _items,
                                                   KURL(),
                                                   m_actionCollection,
                                                   KRootWm::getRootWm()->newMenu() );

   popupMenu->exec( _global );
   delete popupMenu;
}

// -----------------------------------------------------------------------------


kdesktop'KDesktop::slotEnableAction() (./kdebase/kdesktop/desktop.cc:432)

void KDesktop::slotEnableAction( const char * name, bool enabled )
{
  // Hmm, we have one action for paste, not two...
  QCString hackName( name );
  if ( hackName == "pastecopy" || hackName == "pastecut" )
    hackName = "paste";

  KAction * act = m_actionCollection.action( hackName.data() );
  if (!act)
    kdWarning(1202) << "Unknown action " << hackName.data() << " - can't enable" << endl;
  else
    act->setEnabled( enabled );
}

// -----------------------------------------------------------------------------


kdesktop'KDesktop::slotClear() (./kdebase/kdesktop/desktop.cc:448)

void KDesktop::slotClear()
{
    clear();
}

// -----------------------------------------------------------------------------


kdesktop'KDesktop::slotNewItems() (./kdebase/kdesktop/desktop.cc:455)

void KDesktop::slotNewItems( const KonqFileItemList & entries )
{
  KonqFileItemListIterator it(entries);
  for (; it.current(); ++it) {
    KFileIVI* fileICI = new KFileIVI( this, it.current(), iconSize(), false );
    fileICI->setRenameEnabled( false );
    QObject::connect( fileICI, SIGNAL( dropMe( KFileIVI *, QDropEvent * ) ),
                      this, SLOT( slotDropItem( KFileIVI *, QDropEvent * ) ) );

    if ( m_dotDirectory )
    {
      QString group = m_iconPositionGroupPrefix;
      group.append( it.current()->url().filename() );
      if ( m_dotDirectory->hasGroup( group ) )
      {
        m_dotDirectory->setGroup( group );
	int x = m_dotDirectory->readNumEntry( "X" );
	int y = m_dotDirectory->readNumEntry( "Y" );
	fileICI->move( x, y );
      }
    }
 }
}


// -----------------------------------------------------------------------------


kdesktop'KDesktop::slotDeleteItem() (./kdebase/kdesktop/desktop.cc:482)

void KDesktop::slotDeleteItem( KonqFileItem * _fileitem )
{
    // we need to find out the KFileIVI containing the fileitem
    QIconViewItem *it = firstItem();
    while ( it ) {
        if ( ((KFileIVI*)it)->item() == _fileitem ) { // compare the pointers
            delete it;
            break;
        }
        it = it->nextItem();
    }
}

// -----------------------------------------------------------------------------


kdesktop'KDesktop::slotCompleted() (./kdebase/kdesktop/desktop.cc:497)

void KDesktop::slotCompleted()
{
    // Root item ? Store in konqiconviewwidget
    if ( m_dirLister->rootItem() )
      setRootItem( m_dirLister->rootItem() );

    if ( m_dotDirectory )
    {
      delete m_dotDirectory;
      m_dotDirectory = 0;
    }

    slotSaveIconPositions();
}

// -----------------------------------------------------------------------------


kdesktop'KDesktop::slotItemRenamed() (./kdebase/kdesktop/desktop.cc:514)

void KDesktop::slotItemRenamed(QIconViewItem* /*_item*/)
{
    debug("KDesktop::slotItemRenamed()");
}


// -----------------------------------------------------------------------------


kdesktop'KDesktop::showEvent() (./kdebase/kdesktop/desktop.cc:522)

void KDesktop::showEvent( QShowEvent *e )
{
  //HACK to avoid QIconView calling arrangeItemsInGrid (Simon)
  QScrollView::showEvent( e );
}

// -----------------------------------------------------------------------------

// don't hide when someone presses Alt-F4 on us

kdesktop'KDesktop::closeEvent() (./kdebase/kdesktop/desktop.cc:531)

void KDesktop::closeEvent(QCloseEvent *e)
{
    e->ignore();
}