From 145abc15d57fb29701a12e8a14dcb9c1fd72e9be Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Mon, 7 Dec 2020 22:58:44 +0900 Subject: Renaming of files in preparation for code style tools. Signed-off-by: Michele Calgaro --- kdesktop/kdiconview.cpp | 2092 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2092 insertions(+) create mode 100644 kdesktop/kdiconview.cpp (limited to 'kdesktop/kdiconview.cpp') diff --git a/kdesktop/kdiconview.cpp b/kdesktop/kdiconview.cpp new file mode 100644 index 000000000..c8c5a1fe6 --- /dev/null +++ b/kdesktop/kdiconview.cpp @@ -0,0 +1,2092 @@ +/* This file is part of the TDE project + Copyright (C) 1998, 1999 Torben Weis + Copyright (C) 2000, 2001 David Faure + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License version 2 as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kdiconview.h" +#include "krootwm.h" +#include "desktop.h" +#include "kdesktopsettings.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include + +#include "kshadowengine.h" +#include "kdesktopshadowsettings.h" +#include "tdefileividesktop.h" + +// for multihead +extern int kdesktop_screen_number; + +// ----------------------------------------------------------------------------- + +TQRect KDIconView::desktopRect() +{ + return ( kdesktop_screen_number == 0 ) + ? TQApplication::desktop()->geometry() // simple case, or xinerama + : TQApplication::desktop()->screenGeometry( kdesktop_screen_number ); // multi-head +} + +// ----------------------------------------------------------------------------- + +void KDIconView::saveIconPosition(KSimpleConfig *config, int x, int y) +{ + // save the icon position in absolute coordinates + config->writeEntry("Xabs", x); + config->writeEntry("Yabs", y); + + // save also mentioning desktop size + TQRect desk = desktopRect(); + TQString sizeStr = TQString( "_%1x%2" ).arg(desk.width()).arg(desk.height()); + + config->writeEntry("Xabs" + sizeStr, x); + config->writeEntry("Yabs" + sizeStr, y); +} + +// ----------------------------------------------------------------------------- + +void KDIconView::readIconPosition(KSimpleConfig *config, int &x, int &y) +{ + // check if we have the position for the current desktop size + TQRect desk = desktopRect(); + TQString sizeStr = TQString( "_%1x%2" ).arg(desk.width()).arg(desk.height()); + + x = config->readNumEntry("Xabs" + sizeStr, -99999); + + if ( x != -99999 ) + y = config->readNumEntry("Yabs" + sizeStr); + else + { + // not found; use the resolution independent position + x = config->readNumEntry("Xabs", -99999); + + if ( x != -99999 ) + y = config->readNumEntry("Yabs"); + else // for compatibility, read the old iconArea-relative-position + { + // problem here: when reading a position before we know the correct + // desktopIconsArea, the relative position do not make sense + // workaround: use desktopRect() as the allowed size + + TQRect desk = desktopRect(); + TQString X_w = TQString("X %1").arg(desk.width() ); + TQString Y_h = TQString("Y %1").arg(desk.height()); + + x = config->readNumEntry(X_w, -99999); + if ( x != -99999 ) x = config->readNumEntry("X"); + if ( x < 0 ) x += desk.width(); + + y = config->readNumEntry(Y_h, -99999); + if ( y != -99999 ) y = config->readNumEntry("Y"); + if ( y < 0 ) y += desk.height(); + } + } +} + +// ----------------------------------------------------------------------------- + +KDIconView::KDIconView( TQWidget *parent, const char* name ) + : KonqIconViewWidget( parent, name, (WFlags)WResizeNoErase, true ), + m_actionCollection( this, "KDIconView::m_actionCollection" ), + m_accel( 0L ), + m_bNeedRepaint( false ), + m_bNeedSave( false ), + m_autoAlign( false ), + m_hasExistingPos( false ), + m_bEditableDesktopIcons( kapp->authorize("editable_desktop_icons") ), + m_bShowDot( false ), + m_bVertAlign( true ), + m_dirLister( 0L ), + m_mergeDirs(), + m_dotDirectory( 0L ), + m_lastDeletedIconPos(), + m_eSortCriterion( NameCaseInsensitive ), + m_bSortDirectoriesFirst( true ), + m_itemsAlwaysFirst(), + m_enableMedia(false), + m_gotIconsArea(false), + m_needDesktopAlign(true), + m_paOutstandingFreeSpaceOverlaysTimer( 0L ) +{ + setResizeMode( Fixed ); + setIconArea( desktopRect() ); // the default is the whole desktop + + // Initialise the shadow data objects... + m_shadowEngine = new KShadowEngine(new KDesktopShadowSettings(TDEGlobal::config())); + + // Initialize media handler + mMediaListView = new TQListView(); + + connect( TQApplication::clipboard(), TQT_SIGNAL(dataChanged()), this, TQT_SLOT(slotClipboardDataChanged()) ); + + setURL( desktopURL() ); // sets m_url + + m_desktopDirs = TDEGlobal::dirs()->findDirs( "appdata", "Desktop" ); + initDotDirectories(); + + connect( this, TQT_SIGNAL( executed( TQIconViewItem * ) ), + TQT_SLOT( slotExecuted( TQIconViewItem * ) ) ); + connect( this, TQT_SIGNAL( returnPressed( TQIconViewItem * ) ), + TQT_SLOT( slotReturnPressed( TQIconViewItem * ) ) ); + connect( this, TQT_SIGNAL( mouseButtonPressed(int, TQIconViewItem*, const TQPoint&)), + TQT_SLOT( slotMouseButtonPressed(int, TQIconViewItem*, const TQPoint&)) ); + connect( this, TQT_SIGNAL( mouseButtonClicked(int, TQIconViewItem*, const TQPoint&)), + TQT_SLOT( slotMouseButtonClickedKDesktop(int, TQIconViewItem*, const TQPoint&)) ); + connect( this, TQT_SIGNAL( contextMenuRequested(TQIconViewItem*, const TQPoint&)), + TQT_SLOT( slotContextMenuRequested(TQIconViewItem*, const TQPoint&)) ); + + connect( this, TQT_SIGNAL( enableAction( const char * , bool ) ), + TQT_SLOT( slotEnableAction( const char * , bool ) ) ); + + // Hack: KonqIconViewWidget::slotItemRenamed is not virtual :-( + disconnect( this, TQT_SIGNAL(itemRenamed(TQIconViewItem *, const TQString &)), + this, TQT_SLOT(slotItemRenamed(TQIconViewItem *, const TQString &)) ); + connect( this, TQT_SIGNAL(itemRenamed(TQIconViewItem *, const TQString &)), + this, TQT_SLOT(slotItemRenamed(TQIconViewItem *, const TQString &)) ); + + if (!m_bEditableDesktopIcons) + { + setItemsMovable(false); + setAcceptDrops(false); + viewport()->setAcceptDrops(false); + } +} + +KDIconView::~KDIconView() +{ + if (m_dotDirectory && !m_bEditableDesktopIcons) { + m_dotDirectory->rollback(false); // Don't save positions + } + + delete m_dotDirectory; + delete m_dirLister; + delete m_shadowEngine; +} + +void KDIconView::initDotDirectories() +{ + TQStringList dirs = m_desktopDirs; + KURL u = desktopURL(); + if (u.isLocalFile()) { + dirs.prepend(u.path()); + } + + TQString prefix = iconPositionGroupPrefix(); + TQString dotFileName = locateLocal("appdata", "IconPositions"); + if (kdesktop_screen_number != 0) { + dotFileName += "_Desktop" + TQString::number(kdesktop_screen_number); + } + + if (m_dotDirectory && !m_bEditableDesktopIcons) { + m_dotDirectory->rollback(false); // Don't save positions + } + + delete m_dotDirectory; + + m_dotDirectory = new KSimpleConfig( dotFileName ); + // If we don't allow editable desktop icons, empty m_dotDirectory + if (!m_bEditableDesktopIcons) + { + TQStringList groups = m_dotDirectory->groupList(); + TQStringList::ConstIterator gIt = groups.begin(); + TQStringList::ConstIterator gEnd = groups.end(); + for (; gIt != gEnd; ++gIt ) + { + m_dotDirectory->deleteGroup(*gIt, true); + } + } + TQRect desk = desktopRect(); + TQString X_w = TQString( "X %1" ).arg( desk.width() ); + TQString Y_h = TQString( "Y %1" ).arg( desk.height() ); + for ( TQStringList::ConstIterator it = dirs.begin() ; it != dirs.end() ; ++it ) + { + kdDebug(1204) << "KDIconView::initDotDirectories found dir " << *it << endl; + TQString localDotFileName = *it + "/.directory"; + + if (TQFile::exists(localDotFileName)) + { + KSimpleConfig dotDir(localDotFileName, true); // Read only + + TQStringList groups = dotDir.groupList(); + TQStringList::ConstIterator gIt = groups.begin(); + TQStringList::ConstIterator gEnd = groups.end(); + for (; gIt != gEnd; ++gIt ) + { + if ( (*gIt).startsWith(prefix) ) + { + dotDir.setGroup( *gIt ); + m_dotDirectory->setGroup( *gIt ); + + if (!m_dotDirectory->hasKey( X_w )) + { + int x,y; + readIconPosition(&dotDir, x, y); + m_dotDirectory->writeEntry( X_w, x ); + m_dotDirectory->writeEntry( Y_h, y ); // Not persistent! + } + } + } + } + } +} + +void KDIconView::initConfig( bool init ) +{ + //kdDebug() << "initConfig " << init << endl; + + if ( !init ) { + KonqFMSettings::reparseConfiguration(); + KDesktopSettings::self()->readConfig(); + } + + TDEConfig * config = TDEGlobal::config(); + + if ( !init ) { + KDesktopShadowSettings *shadowSettings = static_cast(m_shadowEngine->shadowSettings()); + shadowSettings->setConfig(config); + } + + setMaySetWallpaper(!config->isImmutable() && !TDEGlobal::dirs()->isRestrictedResource("wallpaper")); + m_bShowDot = KDesktopSettings::showHidden(); + m_bVertAlign = KDesktopSettings::vertAlign(); + TQStringList oldPreview = previewSettings(); + setPreviewSettings( KDesktopSettings::preview() ); + + // read arrange configuration + m_eSortCriterion = (SortCriterion)KDesktopSettings::sortCriterion(); + m_bSortDirectoriesFirst = KDesktopSettings::directoriesFirst(); + m_itemsAlwaysFirst = KDesktopSettings::alwaysFirstItems(); // Distributor plug-in + + if (KProtocolInfo::isKnownProtocol(TQString::fromLatin1("media"))) { + m_enableMedia=KDesktopSettings::mediaEnabled(); + } + else { + m_enableMedia=false; + } + TQString tmpList=KDesktopSettings::exclude(); + kdDebug(1204)<<"m_excludeList"<setShowingDotFiles( m_bShowDot ); + m_dirLister->emitChanges(); + } + slotFreeSpaceOverlaySettingChanged(); + + setArrangement(m_bVertAlign ? TopToBottom : LeftToRight); + + if ( KonqIconViewWidget::initConfig( init ) ) + lineupIcons(); // called if the font changed. + + setAutoArrange( false ); + + if ( previewSettings().count() ) + { + for ( TQStringList::ConstIterator it = oldPreview.begin(); it != oldPreview.end(); ++it) + if ( !previewSettings().contains( *it ) ){ + kdDebug(1204) << "Disabling preview for " << *it << endl; + if ( *it == "audio/" ) + disableSoundPreviews(); + else + { + KService::Ptr serv = KService::serviceByDesktopName( *it ); + Q_ASSERT( serv != 0L ); + if ( serv ) + { + setIcons( iconSize( ), serv->property("MimeTypes").toStringList() /* revert no-longer wanted previews to icons */ ); + } + } + } + startImagePreview( TQStringList(), true ); + } + else + { + stopImagePreview(); + setIcons( iconSize(), "*" /* stopImagePreview */ ); + } + + if ( !init ) + updateContents(); +} + +void KDIconView::start() +{ + // We can only start once + Q_ASSERT(!m_dirLister); + if (m_dirLister) { + return; + } + + kdDebug(1204) << "KDIconView::start" << endl; + + // Create the directory lister + m_dirLister = new KDirLister(); + + m_bNeedSave = false; + + connect( m_dirLister, TQT_SIGNAL( clear() ), this, TQT_SLOT( slotClear() ) ); + connect( m_dirLister, TQT_SIGNAL( started(const KURL&) ), this, TQT_SLOT( slotStarted(const KURL&) ) ); + connect( m_dirLister, TQT_SIGNAL( completed() ), this, TQT_SLOT( slotCompleted() ) ); + connect( m_dirLister, TQT_SIGNAL( newItems( const KFileItemList & ) ), this, TQT_SLOT( slotNewItems( const KFileItemList & ) ) ); + connect( m_dirLister, TQT_SIGNAL( deleteItem( KFileItem * ) ), this, TQT_SLOT( slotDeleteItem( KFileItem * ) ) ); + connect( m_dirLister, TQT_SIGNAL( refreshItems( const KFileItemList & ) ), this, TQT_SLOT( slotRefreshItems( const KFileItemList & ) ) ); + + // Start the directory lister ! + m_dirLister->setShowingDotFiles( m_bShowDot ); + kapp->allowURLAction("list", KURL(), url()); + startDirLister(); + createActions(); +} + +void KDIconView::configureMedia() +{ + kdDebug(1204) << "***********KDIconView::configureMedia() " <setMimeExcludeFilter(m_excludedMedia); + m_dirLister->emitChanges(); + updateContents(); + if (m_enableMedia) { + for (KURL::List::Iterator it1=m_mergeDirs.begin();it1!=m_mergeDirs.end();++it1) { + if ((*it1).url()=="media:/") { + return; + } + } + m_mergeDirs.append(KURL("media:/")); + m_dirLister->openURL(KURL("media:/"), true); + } + else { + for (KURL::List::Iterator it2=m_mergeDirs.begin();it2!=m_mergeDirs.end();++it2) { + if ((*it2).url()=="media:/") { + delete m_dirLister; + m_dirLister=0; + start(); + if (m_mergeDirs.contains(*it2)) { + m_mergeDirs.remove(*it2); + m_dirLister->stop("media"); + } + return; + } + } + return; + } +} + +void KDIconView::createActions() +{ + if (m_bEditableDesktopIcons) + { + TDEAction *undo = KStdAction::undo( KonqUndoManager::self(), TQT_SLOT( undo() ), &m_actionCollection, "undo" ); + connect( KonqUndoManager::self(), TQT_SIGNAL( undoAvailable( bool ) ), + undo, TQT_SLOT( setEnabled( bool ) ) ); + connect( KonqUndoManager::self(), TQT_SIGNAL( undoTextChanged( const TQString & ) ), + undo, TQT_SLOT( setText( const TQString & ) ) ); + undo->setEnabled( KonqUndoManager::self()->undoAvailable() ); + + TDEAction* paCut = KStdAction::cut( TQT_TQOBJECT(this), TQT_SLOT( slotCut() ), &m_actionCollection, "cut" ); + TDEShortcut cutShortCut = paCut->shortcut(); + cutShortCut.remove( KKey( SHIFT + Key_Delete ) ); // used for deleting files + paCut->setShortcut( cutShortCut ); + + KStdAction::copy( TQT_TQOBJECT(this), TQT_SLOT( slotCopy() ), &m_actionCollection, "copy" ); + KStdAction::paste( TQT_TQOBJECT(this), TQT_SLOT( slotPaste() ), &m_actionCollection, "paste" ); + TDEAction *pasteTo = KStdAction::paste( TQT_TQOBJECT(this), TQT_SLOT( slotPopupPasteTo() ), &m_actionCollection, "pasteto" ); + pasteTo->setEnabled( false ); // only enabled during popupMenu() + + TDEShortcut reloadShortcut = TDEStdAccel::shortcut(TDEStdAccel::Reload); + new TDEAction( i18n( "&Reload" ), "reload", reloadShortcut, TQT_TQOBJECT(this), TQT_SLOT( refreshIcons() ), &m_actionCollection, "reload" ); + + (void) new TDEAction( i18n( "&Rename" ), /*"editrename",*/ Key_F2, TQT_TQOBJECT(this), TQT_SLOT( renameSelectedItem() ), &m_actionCollection, "rename" ); + (void) new TDEAction( i18n( "&Properties" ), ALT+Key_Return, TQT_TQOBJECT(this), TQT_SLOT( slotProperties() ), &m_actionCollection, "properties" ); + TDEAction* trash = new TDEAction( i18n( "&Move to Trash" ), "edittrash", Key_Delete, &m_actionCollection, "trash" ); + connect( trash, TQT_SIGNAL( activated( TDEAction::ActivationReason, TQt::ButtonState ) ), + this, TQT_SLOT( slotTrashActivated( TDEAction::ActivationReason, TQt::ButtonState ) ) ); + + TDEConfig config("kdeglobals", true, false); + config.setGroup( "KDE" ); + (void) new TDEAction( i18n( "&Delete" ), "edit-delete", SHIFT+Key_Delete, TQT_TQOBJECT(this), TQT_SLOT( slotDelete() ), &m_actionCollection, "del" ); + + // Initial state of the actions (cut/copy/paste/...) + slotSelectionChanged(); + //init paste action + slotClipboardDataChanged(); + } +} + +void KDIconView::rearrangeIcons( SortCriterion sc, bool bSortDirectoriesFirst ) +{ + m_eSortCriterion = sc; + m_bSortDirectoriesFirst = bSortDirectoriesFirst; + rearrangeIcons(); +} + +void KDIconView::rearrangeIcons() +{ + setupSortKeys(); + sort(); // calls arrangeItemsInGrid() which does not honor iconArea() + + if ( m_autoAlign ) + lineupIcons( m_bVertAlign ? TQIconView::TopToBottom : TQIconView::LeftToRight ); // also saves position + else + { + KonqIconViewWidget::lineupIcons(m_bVertAlign ? TQIconView::TopToBottom : TQIconView::LeftToRight); + saveIconPositions(); + } +} + +void KDIconView::lineupIcons() +{ + if ( !m_gotIconsArea ) return; + KonqIconViewWidget::lineupIcons(); + saveIconPositions(); +} + +void KDIconView::setAutoAlign( bool b ) +{ + m_autoAlign = b; + + // Auto line-up icons + if ( b ) { + // set maxItemWidth to ensure sane initial icon layout before the auto align code is fully activated + int sz = iconSize() ? iconSize() : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop ); + setMaxItemWidth( TQMAX( TQMAX( sz, previewIconSize( iconSize() ) ), KonqFMSettings::settings()->iconTextWidth() ) ); + setFont( font() ); // Force calcRect() + + if (!KRootWm::self()->startup) { + lineupIcons(); + } + else { + KRootWm::self()->startup = false; + } + connect( this, TQT_SIGNAL( iconMoved() ), + this, TQT_SLOT( lineupIcons() ) ); + } + else { + // change maxItemWidth, because when grid-align was active, it changed this for the grid + int sz = iconSize() ? iconSize() : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop ); + setMaxItemWidth( TQMAX( TQMAX( sz, previewIconSize( iconSize() ) ), KonqFMSettings::settings()->iconTextWidth() ) ); + setFont( font() ); // Force calcRect() + + disconnect( this, TQT_SIGNAL( iconMoved() ), + this, TQT_SLOT( lineupIcons() ) ); + } +} + +void KDIconView::startDirLister() +{ + // if desktop is resized before start() is called (XRandr) + if (!m_dirLister) return; + + m_dirLister->openURL( url() ); + + // Gather the list of directories to merge into the desktop + // (the main URL is desktopURL(), no need for it in the m_mergeDirs list) + m_mergeDirs.clear(); + for ( TQStringList::ConstIterator it = m_desktopDirs.begin() ; it != m_desktopDirs.end() ; ++it ) + { + kdDebug(1204) << "KDIconView::desktopResized found merge dir " << *it << endl; + KURL u; + u.setPath( *it ); + m_mergeDirs.append( u ); + // And start listing this dir right now + kapp->allowURLAction("list", KURL(), u); + m_dirLister->openURL( u, true ); + } + configureMedia(); +} + +void KDIconView::lineupIcons(TQIconView::Arrangement align) +{ + m_bVertAlign = ( align == TQIconView::TopToBottom ); + setArrangement( m_bVertAlign ? TopToBottom : LeftToRight ); + + if ( m_autoAlign ) + { + KonqIconViewWidget::lineupIcons( align ); + saveIconPositions(); + } + else + rearrangeIcons(); // also saves the position + + KDesktopSettings::setVertAlign( m_bVertAlign ); + KDesktopSettings::writeConfig(); +} + +// Only used for DCOP +TQStringList KDIconView::selectedURLs() +{ + TQStringList seq; + + TQIconViewItem *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; +} + +void KDIconView::recheckDesktopURL() +{ + // Did someone change the path to the desktop ? + kdDebug(1204) << desktopURL().url() << endl; + kdDebug(1204) << url().url() << endl; + if ( desktopURL() != url() ) + { + kdDebug(1204) << "Desktop path changed from " << url().url() << + " to " << desktopURL().url() << endl; + setURL( desktopURL() ); // sets m_url + initDotDirectories(); + m_dirLister->openURL( url() ); + } +} + +KURL KDIconView::desktopURL() +{ + // Support both paths and URLs + TQString desktopPath = TDEGlobalSettings::desktopPath(); + if (kdesktop_screen_number != 0) { + TQString dn = "Desktop"; + dn += TQString::number(kdesktop_screen_number); + desktopPath.replace("Desktop", dn); + } + + KURL desktopURL; + if (desktopPath[0] == '/') + desktopURL.setPath(desktopPath); + else + desktopURL = desktopPath; + + Q_ASSERT( desktopURL.isValid() ); + if ( !desktopURL.isValid() ) { // should never happen + KURL u; + u.setPath( TQDir::homeDirPath() + "/" + "Desktop" + "/" ); + return u; + } + + return desktopURL; +} + +void KDIconView::contentsMousePressEvent( TQMouseEvent *e ) +{ + if (!m_dirLister) return; + //kdDebug(1204) << "KDIconView::contentsMousePressEvent" << endl; + // TQIconView, as of Qt 2.2, doesn't emit mouseButtonPressed for LMB on background + if ( e->button() == Qt::LeftButton && KRootWm::self()->hasLeftButtonMenu() ) + { + TQIconViewItem *item = findItem( e->pos() ); + if ( !item ) + { + // Left click menu + KRootWm::self()->mousePressed( e->globalPos(), e->button() ); + return; + } + } + KonqIconViewWidget::contentsMousePressEvent( e ); +} + +void KDIconView::mousePressEvent( TQMouseEvent *e ) +{ + KRootWm::self()->mousePressed( e->globalPos(), e->button() ); +} + +void KDIconView::wheelEvent( TQWheelEvent* e ) +{ + if (!m_dirLister) return; + //kdDebug(1204) << "KDIconView::wheelEvent" << endl; + + TQIconViewItem *item = findItem( e->pos() ); + if ( !item ) + { + emit wheelRolled( e->delta() ); + return; + } + + KonqIconViewWidget::wheelEvent( e ); +} + +void KDIconView::slotProperties() +{ + KFileItemList selectedFiles = selectedFileItems(); + + if( selectedFiles.isEmpty() ) + return; + + (void) new KPropertiesDialog( selectedFiles ); +} + +void KDIconView::slotContextMenuRequested(TQIconViewItem *_item, const TQPoint& _global) +{ + if (_item) + { + ((KFileIVI*)_item)->setSelected( true ); + popupMenu( _global, selectedFileItems() ); + } +} + +void KDIconView::slotMouseButtonPressed(int _button, TQIconViewItem* _item, const TQPoint& _global) +{ + //kdDebug(1204) << "KDIconView::slotMouseButtonPressed" << endl; + if (!m_dirLister) return; + m_lastDeletedIconPos = TQPoint(); // user action -> not renaming an icon + if(!_item) { + KRootWm::self()->mousePressed( _global, _button ); + } +} + +void KDIconView::slotMouseButtonClickedKDesktop(int _button, TQIconViewItem* _item, const TQPoint&) +{ + if (!m_dirLister) return; + //kdDebug(1204) << "KDIconView::slotMouseButtonClickedKDesktop" << endl; + if ( _item && _button == Qt::MidButton ) { + slotExecuted(_item); + } +} + +// ----------------------------------------------------------------------------- + +void KDIconView::slotReturnPressed( TQIconViewItem *item ) +{ + if (item && item->isSelected()) { + slotExecuted(item); + } +} + +// ----------------------------------------------------------------------------- + +void KDIconView::slotExecuted( TQIconViewItem *item ) +{ + kapp->propagateSessionManager(); + m_lastDeletedIconPos = TQPoint(); // user action -> not renaming an icon + if (item) { + visualActivate(item); + ((KFileIVI*)item)->returnPressed(); + } +} + +// ----------------------------------------------------------------------------- + +void KDIconView::slotCut() +{ + cutSelection(); +} + +// ----------------------------------------------------------------------------- + +void KDIconView::slotCopy() +{ + copySelection(); +} + +// ----------------------------------------------------------------------------- + +void KDIconView::slotPaste() +{ + KonqOperations::doPaste(this, url(), KRootWm::self()->desktopMenuPosition()); +} + +void KDIconView::slotPopupPasteTo() +{ + Q_ASSERT( !m_popupURL.isEmpty() ); + if ( !m_popupURL.isEmpty() ) + paste( m_popupURL ); +} + +// These two functions and the following class are all lifted from desktopbehavior_impl.cpp to handle the media icons +class DesktopBehaviorMediaItem : public TQCheckListItem +{ +public: + DesktopBehaviorMediaItem(TQListView *parent, const TQString name, const TQString mimetype, bool on) + : TQCheckListItem(parent, name, CheckBox), + m_mimeType(mimetype){setOn(on);} + + const TQString &mimeType() const { return m_mimeType; } + +private: + TQString m_mimeType; +}; + +void KDIconView::fillMediaListView() +{ + g_pConfig = new TDEConfig("kdesktoprc"); + mMediaListView->hide(); + mMediaListView->clear(); + KMimeType::List mimetypes = KMimeType::allMimeTypes(); + TQValueListIterator it2(mimetypes.begin()); + g_pConfig->setGroup( "Media" ); + TQString excludedMedia=g_pConfig->readEntry("exclude","media/hdd_mounted,media/hdd_unmounted,media/floppy_unmounted,media/cdrom_unmounted,media/floppy5_unmounted"); + for (; it2 != mimetypes.end(); ++it2) { + if ( ((*it2)->name().startsWith("media/")) ) + { + bool ok=excludedMedia.contains((*it2)->name())==0; + new DesktopBehaviorMediaItem (mMediaListView, (*it2)->comment(), (*it2)->name(),ok); + } + } + delete g_pConfig; +} + +void KDIconView::saveMediaListView() +{ + g_pConfig = new TDEConfig("kdesktoprc"); + g_pConfig->setGroup( "Media" ); + TQStringList exclude; + for (DesktopBehaviorMediaItem *it=static_cast(mMediaListView->firstChild()); + it; it=static_cast(it->nextSibling())) + { + if (!it->isOn()) exclude << it->mimeType(); + } + g_pConfig->writeEntry("exclude",exclude); + g_pConfig->sync(); + + // Reload kdesktop configuration to apply changes + TQByteArray data; + int konq_screen_number = TDEApplication::desktop()->primaryScreen(); + TQCString appname; + if (konq_screen_number == 0) + appname = "kdesktop"; + else + appname.sprintf("kdesktop-screen-%d", konq_screen_number); + kapp->dcopClient()->send( appname, "KDesktopIface", "configure()", data ); + delete g_pConfig; +} + +void KDIconView::removeBuiltinIcon(TQString iconName) +{ + DesktopBehaviorMediaItem *changeItem; + fillMediaListView(); + changeItem = static_cast(mMediaListView->findItem(iconName, 0)); + if (changeItem != 0) { + changeItem->setOn(false); + } + saveMediaListView(); + KMessageBox::information(0, i18n("You have chosen to remove a system icon") + TQString(".\n") + i18n("You can restore this icon in the future through the") + TQString(" \"") + ("Device Icons") + TQString("\" ") + i18n("tab in the") + TQString(" \"") + i18n("Behavior") + TQString("\" ") + i18n("pane of the Desktop Settings control module."), "System Icon Removed", "sysiconremovedwarning"); +} + +/** + * The files on the desktop come from a variety of sources. + * If an attempt is made to delete a .desktop file that does + * not originate from the users own Desktop directory then + * a .desktop file with "Hidden=true" is written to the users + * own Desktop directory to hide the file. + * + * Returns true if all selected items have been deleted. + * Returns false if there are selected items remaining that + * still need to be deleted in a regular fashion. + */ +bool KDIconView::deleteGlobalDesktopFiles() +{ + KURL desktop_URL = desktopURL(); + if (!desktop_URL.isLocalFile()) + return false; // Dunno how to do this. + + TQString desktopPath = desktop_URL.path(); + + bool itemsLeft = false; + TQIconViewItem *it = 0; + TQIconViewItem *nextIt = firstItem(); + for (; (it = nextIt); ) + { + nextIt = it->nextItem(); + if ( !it->isSelected() ) + continue; + + KFileItem *fItem = ((KFileIVI *)it)->item(); + if (fItem->url().path().startsWith(desktopPath)) + { + itemsLeft = true; + continue; // File is in users own Desktop directory + } + + if (!isDesktopFile(fItem)) + { + itemsLeft = true; + continue; // Not a .desktop file + } + + // Ignore these special files + // Name URL Type OnlyShowIn + // My Documents XDG_DOCUMENTS_DIR Application TDE; + // My Computer media:/ Link TDE; + // My Network Places remote:/ Link TDE; + // Printers [exec] kjobviewer --all --show %i %m Application TDE; + // Trash trash:/ Link TDE; + // Web Browser kfmclient openBrowser %u Application TDE; + + if ( isDesktopFile(fItem) ) { + KSimpleConfig cfg( fItem->url().path(), true ); + cfg.setDesktopGroup(); + if ( cfg.readEntry( "X-Trinity-BuiltIn" ) == "true" ) { + removeBuiltinIcon(cfg.readEntry( "Name" )); + continue; + } + } + + KDesktopFile df(desktopPath + fItem->url().fileName()); + df.writeEntry("Hidden", true); + df.sync(); + + delete it; + } + return !itemsLeft; +} + +void KDIconView::slotTrashActivated( TDEAction::ActivationReason reason, TQt::ButtonState state ) +{ + if (deleteGlobalDesktopFiles()) + return; // All items deleted + + if ( reason == TDEAction::PopupMenuActivation && ( state & TQt::ShiftButton ) ) + KonqOperations::del(this, KonqOperations::DEL, selectedUrls()); + else + KonqOperations::del(this, KonqOperations::TRASH, selectedUrls()); +} + +void KDIconView::slotDelete() +{ + if (deleteGlobalDesktopFiles()) + return; // All items deleted + KonqOperations::del(this, KonqOperations::DEL, selectedUrls()); +} + +// ----------------------------------------------------------------------------- + +// This method is called when right-clicking over one or more items +// Not to be confused with the global popup-menu, KRootWm, when doing RMB on the desktop +void KDIconView::popupMenu( const TQPoint &_global, const KFileItemList& _items ) +{ + if (!kapp->authorize("action/kdesktop_rmb")) return; + if (!m_dirLister) return; + if ( _items.count() == 1 ) + m_popupURL = _items.getFirst()->url(); + + TDEAction* pasteTo = m_actionCollection.action( "pasteto" ); + if (pasteTo) + pasteTo->setEnabled( m_actionCollection.action( "paste" )->isEnabled() ); + + bool hasMediaFiles = false; + KFileItemListIterator it(_items); + for (; it.current() && !hasMediaFiles; ++it) { + hasMediaFiles = it.current()->url().protocol() == "media"; + } + + KParts::BrowserExtension::PopupFlags itemFlags = KParts::BrowserExtension::DefaultPopupItems; + if ( hasMediaFiles ) + itemFlags |= KParts::BrowserExtension::NoDeletion; + KonqPopupMenu * popupMenu = new KonqPopupMenu( KonqBookmarkManager::self(), _items, + url(), + m_actionCollection, + KRootWm::self()->newMenu(), + this, + KonqPopupMenu::ShowProperties | KonqPopupMenu::ShowNewWindow, + itemFlags ); + + popupMenu->exec( _global ); + delete popupMenu; + m_popupURL = KURL(); + if (pasteTo) + pasteTo->setEnabled( false ); +} + +void KDIconView::slotNewMenuActivated() +{ + //kdDebug(1204) << "KDIconView::slotNewMenuActivated" << endl; + // New /