From ad6f3f6402df4bdf88672d511e21ab1e9b88d978 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 (cherry picked from commit 145abc15d57fb29701a12e8a14dcb9c1fd72e9be) --- kdesktop/CMakeLists.txt | 8 +- kdesktop/Makefile.am | 10 +- kdesktop/bgmanager.cc | 1109 ------------- kdesktop/bgmanager.cpp | 1109 +++++++++++++ kdesktop/desktop.cc | 1197 -------------- kdesktop/desktop.cpp | 1197 ++++++++++++++ kdesktop/init.cc | 247 --- kdesktop/init.cpp | 247 +++ kdesktop/kcustommenu.cc | 111 -- kdesktop/kcustommenu.cpp | 111 ++ kdesktop/kdesktop.kcfg | 14 +- kdesktop/kdiconview.cc | 2092 ----------------------- kdesktop/kdiconview.cpp | 2092 +++++++++++++++++++++++ kdesktop/krootwm.cc | 922 ----------- kdesktop/krootwm.cpp | 922 +++++++++++ kdesktop/krootwm.h | 2 +- kdesktop/kwebdesktop/kwebdesktop.kcfg | 2 +- kdesktop/lock/CMakeLists.txt | 4 +- kdesktop/lock/Makefile.am | 2 +- kdesktop/lock/autologout.cc | 132 -- kdesktop/lock/autologout.cpp | 132 ++ kdesktop/lock/infodlg.cc | 147 -- kdesktop/lock/infodlg.cpp | 147 ++ kdesktop/lock/lockdlg.cc | 900 ---------- kdesktop/lock/lockdlg.cpp | 900 ++++++++++ kdesktop/lock/lockprocess.cc | 2940 --------------------------------- kdesktop/lock/lockprocess.cpp | 2940 +++++++++++++++++++++++++++++++++ kdesktop/lock/main.cc | 553 ------- kdesktop/lock/main.cpp | 553 +++++++ kdesktop/lock/querydlg.cc | 161 -- kdesktop/lock/querydlg.cpp | 161 ++ kdesktop/lock/sakdlg.cc | 151 -- kdesktop/lock/sakdlg.cpp | 151 ++ kdesktop/lock/securedlg.cc | 215 --- kdesktop/lock/securedlg.cpp | 215 +++ kdesktop/lockeng.cc | 923 ----------- kdesktop/lockeng.cpp | 923 +++++++++++ kdesktop/main.cc | 294 ---- kdesktop/main.cpp | 294 ++++ kdesktop/pixmapserver.cc | 254 --- kdesktop/pixmapserver.cpp | 254 +++ kdesktop/xautolock.cc | 289 ---- kdesktop/xautolock.cpp | 289 ++++ 43 files changed, 12658 insertions(+), 12658 deletions(-) delete mode 100644 kdesktop/bgmanager.cc create mode 100644 kdesktop/bgmanager.cpp delete mode 100644 kdesktop/desktop.cc create mode 100644 kdesktop/desktop.cpp delete mode 100644 kdesktop/init.cc create mode 100644 kdesktop/init.cpp delete mode 100644 kdesktop/kcustommenu.cc create mode 100644 kdesktop/kcustommenu.cpp delete mode 100644 kdesktop/kdiconview.cc create mode 100644 kdesktop/kdiconview.cpp delete mode 100644 kdesktop/krootwm.cc create mode 100644 kdesktop/krootwm.cpp delete mode 100644 kdesktop/lock/autologout.cc create mode 100644 kdesktop/lock/autologout.cpp delete mode 100644 kdesktop/lock/infodlg.cc create mode 100644 kdesktop/lock/infodlg.cpp delete mode 100644 kdesktop/lock/lockdlg.cc create mode 100644 kdesktop/lock/lockdlg.cpp delete mode 100644 kdesktop/lock/lockprocess.cc create mode 100644 kdesktop/lock/lockprocess.cpp delete mode 100644 kdesktop/lock/main.cc create mode 100644 kdesktop/lock/main.cpp delete mode 100644 kdesktop/lock/querydlg.cc create mode 100644 kdesktop/lock/querydlg.cpp delete mode 100644 kdesktop/lock/sakdlg.cc create mode 100644 kdesktop/lock/sakdlg.cpp delete mode 100644 kdesktop/lock/securedlg.cc create mode 100644 kdesktop/lock/securedlg.cpp delete mode 100644 kdesktop/lockeng.cc create mode 100644 kdesktop/lockeng.cpp delete mode 100644 kdesktop/main.cc create mode 100644 kdesktop/main.cpp delete mode 100644 kdesktop/pixmapserver.cc create mode 100644 kdesktop/pixmapserver.cpp delete mode 100644 kdesktop/xautolock.cc create mode 100644 kdesktop/xautolock.cpp (limited to 'kdesktop') diff --git a/kdesktop/CMakeLists.txt b/kdesktop/CMakeLists.txt index a4714ce59..5ee2746cc 100644 --- a/kdesktop/CMakeLists.txt +++ b/kdesktop/CMakeLists.txt @@ -81,13 +81,13 @@ tde_add_executable( kcheckrunning ##### kdesktop (tdeinit) ######################## set( target kdesktop ) -set_property( SOURCE lockeng.cc APPEND PROPERTY COMPILE_DEFINITIONS KDE_CONFDIR="${TDE_CONFIG_DIR}" ) +set_property( SOURCE lockeng.cpp APPEND PROPERTY COMPILE_DEFINITIONS KDE_CONFDIR="${TDE_CONFIG_DIR}" ) set( ${target}_SRCS - main.cc krootwm.cc xautolock.cc kdiconview.cc init.cc - desktop.cc lockeng.cc KDesktopIface.skel bgmanager.cc + main.cpp krootwm.cpp xautolock.cpp kdiconview.cpp init.cpp + desktop.cpp lockeng.cpp KDesktopIface.skel bgmanager.cpp KScreensaverIface.skel minicli.cpp KBackgroundIface.skel - pixmapserver.cc kcustommenu.cc startupid.cpp minicli_ui.ui + pixmapserver.cpp kcustommenu.cpp startupid.cpp minicli_ui.ui xautolock_diy.c xautolock_engine.c kshadowengine.cpp kshadowsettings.cpp kdesktopshadowsettings.cpp tdefileividesktop.cpp kdesktopapp.cpp diff --git a/kdesktop/Makefile.am b/kdesktop/Makefile.am index bef2d3884..393b3c760 100644 --- a/kdesktop/Makefile.am +++ b/kdesktop/Makefile.am @@ -17,10 +17,10 @@ libkdesktopsettings_la_LDFLAGS = $(all_libraries) -no-undefined libkdesktopsettings_la_LIBADD = $(LIB_TDECORE) libkdesktopsettings_la_SOURCES = kdesktopsettings.kcfgc tdelaunchsettings.kcfgc -kdesktop_la_SOURCES = main.cc krootwm.cc xautolock.cc kdiconview.cc desktop.cc \ - lockeng.cc KDesktopIface.skel \ - bgmanager.cc init.cc KScreensaverIface.skel \ - minicli.cpp KBackgroundIface.skel pixmapserver.cc kcustommenu.cc \ +kdesktop_la_SOURCES = main.cpp krootwm.cpp xautolock.cpp kdiconview.cpp desktop.cpp \ + lockeng.cpp KDesktopIface.skel \ + bgmanager.cpp init.cpp KScreensaverIface.skel \ + minicli.cpp KBackgroundIface.skel pixmapserver.cpp kcustommenu.cpp \ startupid.cpp minicli_ui.ui xautolock_diy.c xautolock_engine.c \ kshadowengine.cpp kshadowsettings.cpp \ kdesktopshadowsettings.cpp tdefileividesktop.cpp \ @@ -59,7 +59,7 @@ startupid.lo: tdelaunchsettings.h messages: rc.cpp $(EXTRACTRC) lock/*.ui >> rc.cpp - $(XGETTEXT) lock/*.cc *.cc *.cpp *.h -o $(podir)/kdesktop.pot + $(XGETTEXT) lock/*.cpp *.cpp *.h -o $(podir)/kdesktop.pot menu_DATA = kdesktop_custom_menu1 kdesktop_custom_menu2 menudir = $(kde_confdir) diff --git a/kdesktop/bgmanager.cc b/kdesktop/bgmanager.cc deleted file mode 100644 index 7e90e8fca..000000000 --- a/kdesktop/bgmanager.cc +++ /dev/null @@ -1,1109 +0,0 @@ -/* - * - * This file is part of the KDE project, module kdesktop. - * Copyright (C) 1999,2000 Geert Jansen - * - * You can Freely distribute this program under the GNU General Public - * License. See the file "COPYING" for the exact licensing terms. - */ - -#include -#include "bgrender.h" -#include "bgmanager.h" -#include "bgdefaults.h" -#include "kdesktopsettings.h" -#include "bgsettings.h" -#include "kdesktopapp.h" - -#include "KCrossBGRender.h" -#include "crossfade.h" - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#ifndef None -#define None 0L -#endif - -#ifdef COMPOSITE -# include -# include -# include -#endif - -#include "pixmapserver.h" - -template class TQPtrVector; -template class TQPtrVector; -template class TQMemArray; - -static Atom prop_root; -static bool properties_inited = false; - -extern bool argb_visual; -extern KDesktopApp *myApp; - -/**** KBackgroundManager ****/ - -KBackgroundManager::KBackgroundManager(TQWidget *desktop, KWinModule* twinModule) - : KBackgroundIface() -{ - if( !properties_inited ) - { - prop_root = XInternAtom(tqt_xdisplay(), "_XROOTPMAP_ID", False); - properties_inited = true; - } - m_bBgInitDone = false; - m_bEnabled = true; - - m_pDesktop = desktop; - if (desktop == 0L) - desktop = TQT_TQWIDGET(TDEApplication::desktop()->screen()); - - m_Renderer.resize( 1 ); - m_Cache.resize( 1 ); - - m_Serial = 0; m_Hash = 0; - m_pConfig = TDEGlobal::config(); - m_bExport = m_bCommon = m_bInit = false; - m_pKwinmodule = twinModule; - m_pPixmapServer = new KPixmapServer(); - m_xrootpmap = None; - - for (unsigned i=0; ipixmap = 0L; - m_Cache[i]->hash = 0; - m_Cache[i]->exp_from = -1; - m_Renderer.insert (i, new KVirtualBGRenderer(i,m_pConfig)); - connect(m_Renderer[i], TQT_SIGNAL(imageDone(int)), TQT_SLOT(slotImageDone(int))); - m_Renderer[i]->enableTiling( true ); // optimize - } - -#ifdef COMPOSITE - m_tPixmap = new KPixmap(kapp->desktop()->size()); - m_tPixmap->fill(TQColor(0, 0x0)); - connect(myApp, TQT_SIGNAL(cmBackgroundChanged( bool )), - TQT_SLOT(slotCmBackgroundChanged( bool ))); -#endif - - configure(); - - m_pTimer = new TQTimer(this); - connect(m_pTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotTimeout())); - m_pTimer->start( 60000 ); - - /*CrossFade's config*/ - m_crossTimer = new TQTimer(this); - connect(m_crossTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotCrossFadeTimeout())); - resizingDesktop = true; - /*Ends here*/ - - - connect(m_pKwinmodule, TQT_SIGNAL(currentDesktopChanged(int)), - TQT_SLOT(slotChangeDesktop(int))); - connect(m_pKwinmodule, TQT_SIGNAL(numberOfDesktopsChanged(int)), - TQT_SLOT(slotChangeNumberOfDesktops(int))); - connect(m_pKwinmodule, TQT_SIGNAL(currentDesktopViewportChanged(int, const TQPoint&)), - TQT_SLOT(slotChangeViewport(int, const TQPoint&))); - - -#if (TQT_VERSION-0 >= 0x030200) - connect( kapp->desktop(), TQT_SIGNAL( resized( int )), TQT_SLOT( desktopResized())); // RANDR support -#endif - - TQSize s(m_pKwinmodule->numberOfViewports(m_pKwinmodule->currentDesktop())); - m_numberOfViewports = s.width() * s.height(); - if (m_numberOfViewports < 1) { - m_numberOfViewports = 1; - } - for (signed j=0;j<(m_pKwinmodule->numberOfDesktops() * m_numberOfViewports);j++) { - renderBackground(j); - } -} - - -KBackgroundManager::~KBackgroundManager() -{ - for (unsigned i=0; ipixmap; - delete m_Cache[i]; - } -} - - -void KBackgroundManager::applyExport(bool exp) -{ - if (exp == m_bExport) - return; - - // If export mode changed from true -> false, remove all shared pixmaps. - // If it changed false -> true force a redraw because the current screen - // image might not have an associated pixmap in the cache. - if (!exp) - { - for (unsigned i=0; i true, remove all cache entries, except - // at index 0 if exports are on. - if (m_bCommon) - { - if (!m_bExport) - removeCache(0); - for (unsigned i=1; ireparseConfiguration(); - KDesktopSettings::self()->readConfig(); - - // Read individual settings - KVirtualBGRenderer *r; - for (unsigned i=0; ihash(); - r->load(i,false); - if ((r->hash() != ohash)) - removeCache(i); - } - - applyCommon(KDesktopSettings::commonDesktop()); - - bool limit = KDesktopSettings::limitCache(); - int size = KDesktopSettings::cacheSize() * 1024; - applyCache(limit, size); - - // Repaint desktop - slotChangeDesktop(0); - - // Redraw all desktops so that applications relying on exported data, e.g. kpager, continue to work properly - TQSize s(m_pKwinmodule->numberOfViewports(m_pKwinmodule->currentDesktop())); - m_numberOfViewports = s.width() * s.height(); - if (m_numberOfViewports < 1) { - m_numberOfViewports = 1; - } - for (signed j=0;j<(m_pKwinmodule->numberOfDesktops() * m_numberOfViewports);j++) { - renderBackground(j); - } -} - - -int KBackgroundManager::realDesktop() -{ - int desk = m_pKwinmodule->currentDesktop(); - if (desk) desk--; - return desk; -} - - -int KBackgroundManager::effectiveDesktop() -{ - TQSize s(m_pKwinmodule->numberOfViewports(m_pKwinmodule->currentDesktop())); - m_numberOfViewports = s.width() * s.height(); - - if (m_numberOfViewports > 1) { - if (m_bCommon) { - return 0; - } - else { - TQPoint vx(m_pKwinmodule->currentViewport(m_pKwinmodule->currentDesktop())); - return (realDesktop() * m_numberOfViewports) + ((vx.x() * vx.y()) - 1); - } - } - else { - return m_bCommon ? 0 : realDesktop(); - } -} - - -/* - * Number of desktops changed - */ -void KBackgroundManager::slotChangeNumberOfDesktops(int num) -{ - TQSize s(m_pKwinmodule->numberOfViewports(m_pKwinmodule->currentDesktop())); - m_numberOfViewports = s.width() * s.height(); - if (m_numberOfViewports < 1) { - m_numberOfViewports = 1; - } - num = (num * m_numberOfViewports); - - if (m_Renderer.size() == (unsigned) num) - return; - - if (m_Renderer.size() > (unsigned) num) - { - for (unsigned i=num; iisActive()) - m_Renderer[i]->stop(); - delete m_Renderer[i]; - removeCache(i); - } - for (unsigned i=num; ipixmap = 0L; - m_Cache[i]->hash = 0; - m_Cache[i]->exp_from = -1; - m_Renderer.insert(i, new KVirtualBGRenderer(i,m_pConfig)); - connect(m_Renderer[i], TQT_SIGNAL(imageDone(int)), TQT_SLOT(slotImageDone(int))); - m_Renderer[i]->enableTiling( true ); // optimize - } - } -} - -/* - * Call this when the desktop has been changed. - * Desk is in KWin convention: [1..desks], instead of [0..desks-1]. - * 0 repaints the current desktop. - */ -void KBackgroundManager::slotChangeDesktop(int desk) -{ - resizingDesktop = true; - TQSize s(m_pKwinmodule->numberOfViewports(m_pKwinmodule->currentDesktop())); - m_numberOfViewports = s.width() * s.height(); - if (m_numberOfViewports < 1) { - m_numberOfViewports = 1; - } - - if (desk == 0) - desk = realDesktop(); - else - desk--; - - // Lazy initialisation of # of desktops - if ((unsigned)(m_pKwinmodule->numberOfDesktops() * m_numberOfViewports) >= m_Renderer.size()) - slotChangeNumberOfDesktops( m_pKwinmodule->numberOfDesktops() * m_numberOfViewports); - - int edesk = effectiveDesktop(); - m_Serial++; - - // If the background is the same: do nothing - if ((m_Hash == m_Renderer[edesk]->hash()) && (desk != 0)) - { - exportBackground(m_Current, desk); - return; - } - m_Renderer[edesk]->stop(); - m_Renderer[edesk]->cleanup(); - - // If we have the background already rendered: set it - for (unsigned i=0; ipixmap) - continue; - if (m_Cache[i]->hash != m_Renderer[edesk]->hash()) - continue; - if (desk == 0) - continue; -// kdDebug() << "slotChangeDesktop i=" << i << endl; - setPixmap(m_Cache[i]->pixmap, m_Cache[i]->hash, i); - m_Cache[i]->atime = m_Serial; - exportBackground(i, desk); - return; - } - - // Do we have this or an identical config already running? - for (unsigned i=0; ihash() == m_Renderer[edesk]->hash()) && (m_Renderer[i]->isActive())) && (desk != 0)) { - return; - } - } - - renderBackground(edesk); -} - -/* - * Call this when the viewport has been changed. - * Desk is in KWin convention: [1..desks], instead of [0..desks-1]. - * 0 repaints the current viewport. - */ -void KBackgroundManager::slotChangeViewport(int desk, const TQPoint& viewport) -{ - TQSize s(m_pKwinmodule->numberOfViewports(m_pKwinmodule->currentDesktop())); - m_numberOfViewports = s.width() * s.height(); - if (m_numberOfViewports < 1) { - m_numberOfViewports = 1; - } - - if (desk == 0) - desk = realDesktop(); - else - desk--; - - // Lazy initialisation of # of desktops - if ((unsigned)(m_pKwinmodule->numberOfDesktops() * m_numberOfViewports) >= m_Renderer.size()) - slotChangeNumberOfDesktops( m_pKwinmodule->numberOfDesktops() * m_numberOfViewports ); - - int edesk = effectiveDesktop(); - m_Serial++; - - // If the background is the same: do nothing - if ((m_Hash == m_Renderer[edesk]->hash()) && (desk != 0)) - { - exportBackground(m_Current, desk); - return; - } - m_Renderer[edesk]->stop(); - m_Renderer[edesk]->cleanup(); - - // If we have the background already rendered: set it - for (unsigned i=0; ipixmap) - continue; - if (m_Cache[i]->hash != m_Renderer[edesk]->hash()) - continue; - if (desk == 0) - continue; -// kdDebug() << "slotChangeDesktop i=" << i << endl; - - //KPixmap * viewport_background = new KPixmap(TQPixmap(m_Cache[i]->pixmap->width()*s.width(), m_Cache[i]->pixmap->height()*s.height())); - //setPixmap(viewport_background, m_Cache[i]->hash, i); - //delete viewport_background; - - setPixmap(m_Cache[i]->pixmap, m_Cache[i]->hash, i); - m_Cache[i]->atime = m_Serial; - exportBackground(i, desk); - return; - } - - // Do we have this or an identical config already running? - for (unsigned i=0; ihash() == m_Renderer[edesk]->hash()) && (m_Renderer[i]->isActive())) && (desk != 0)) - return; - } - - renderBackground(edesk); -} - - -/* - * Share a desktop pixmap. - */ -void KBackgroundManager::exportBackground(int pixmap, int desk) -{ - if (!m_bExport || (m_Cache[desk]->exp_from == pixmap)) - return; - - m_Cache[desk]->exp_from = pixmap; - m_pPixmapServer->add(KRootPixmap::pixmapName(desk+1), - m_Cache[pixmap]->pixmap); - KIPC::sendMessageAll(KIPC::BackgroundChanged, desk+1); -} - - -/* - * Paint the pixmap to the root window. - */ -void KBackgroundManager::setPixmap(KPixmap *pm, int hash, int desk) -{ - KPixmap *ep = pm; - -#ifdef COMPOSITE - if (argb_visual && (KDesktopSettings::backgroundOpacity() < 100 - || myApp->cmBackground())) - { - ep = m_tPixmap; - if (KDesktopSettings::backgroundOpacity() > 0 && pm - && !myApp->cmBackground()) - { - XRenderPictFormat *format; - format = XRenderFindStandardFormat (tqt_xdisplay(), PictStandardARGB32); - - XRenderColor fillColor; - - int color = KDesktopSettings::backgroundOpacity() * 0xffff / 100; - fillColor.red = color; - fillColor.green = color; - fillColor.blue = color; - fillColor.alpha = color; - - Picture fill = XRenderCreateSolidFill (tqt_xdisplay(), &fillColor); - Picture src = XRenderCreatePicture(tqt_xdisplay(), pm->handle(), - format, 0, NULL); - Picture dst = XRenderCreatePicture(tqt_xdisplay(), ep->handle(), - format, 0, NULL); - - XRenderComposite (tqt_xdisplay(), PictOpSrc, src, fill, dst, 0, 0, 0, - 0, 0, 0, pm->width(), pm->height()); - - XRenderFreePicture (tqt_xdisplay(), fill); - XRenderFreePicture (tqt_xdisplay(), src); - XRenderFreePicture (tqt_xdisplay(), dst); - } - } -#endif - - if (m_pDesktop) - { - TQScrollView* sv = dynamic_cast( m_pDesktop ); - if ( sv ) { - // Qt eats repaint events in this case :-(( - sv->viewport()->update(); - } - m_pDesktop->setErasePixmap(*ep); - m_pDesktop->repaint(); - static bool root_cleared = false; - if( !root_cleared ) - { // clear the root window pixmap set by tdm - root_cleared = true; - TQTimer::singleShot( 0, this, TQT_SLOT( clearRoot())); - // but make the pixmap visible until m_pDesktop is visible - TQT_TQWIDGET(TDEApplication::desktop()->screen())->setErasePixmap(*ep); - TQT_TQWIDGET(TDEApplication::desktop()->screen())->erase(); - } - } - else - { - TQT_TQWIDGET(TDEApplication::desktop()->screen())->setErasePixmap(*ep); - TQT_TQWIDGET(TDEApplication::desktop()->screen())->erase(); - } - - // and export it via Esetroot-style for gnome/GTK apps to share in the pretties - Pixmap bgPm = pm->handle(); // fetch the actual X handle to it - //kdDebug() << "Esetroot compat: setting pixmap to " << bgPm << endl; - - // don't set the ESETROOT_PMAP_ID property - that would result in possible XKillClient() - // done on kdesktop - - XChangeProperty(tqt_xdisplay(), tqt_xrootwin(), prop_root, XA_PIXMAP, 32, PropModeReplace, - (unsigned char *) &bgPm, 1); - m_xrootpmap = bgPm; - - m_Hash = hash; - m_Current = desk; -} - -void KBackgroundManager::clearRoot() -{ - TQT_TQWIDGET(TDEApplication::desktop()->screen())->setErasePixmap( TQPixmap()); - TQT_TQWIDGET(TDEApplication::desktop()->screen())->erase(); -} - -/* - * Start the render of a desktop background. - */ -void KBackgroundManager::renderBackground(int desk) -{ - KVirtualBGRenderer *r = m_Renderer[desk]; - if (r->isActive()) - { - kdDebug() << "renderer " << desk << " already active" << endl; - return; - } - - r->start(); -} - - -/* - * This slot is called when the Timeout is executed - */ -void KBackgroundManager::slotCrossFadeTimeout() -{ - KVirtualBGRenderer *r = m_Renderer[fadeDesk]; - if (crossInit) { - mBenchmark.start(); - } - - if (mAlpha <= 0.0 || mBenchmark.elapsed() > 300 ) { - mAlpha = 1; - m_crossTimer->stop(); - KPixmap pixm(mNextScreen); - setPixmap(&pixm, r->hash(), fadeDesk); - return; - } - // Reset Timer - mBenchmark.start(); - - TQPixmap dst = crossFade(*mOldScreen, mNextScreen, mAlpha, crossInit); - KPixmap pixm(dst); - setPixmap(&pixm, r->hash(), fadeDesk); - - mAlpha -=0.03; - crossInit = false; -} - - -/* - * This slot is called when a renderer is done. - */ -void KBackgroundManager::slotImageDone(int desk) -{ - TQSize s(m_pKwinmodule->numberOfViewports(m_pKwinmodule->currentDesktop())); - m_numberOfViewports = s.width() * s.height(); - if (m_numberOfViewports < 1) { - m_numberOfViewports = 1; - } - - KPixmap *pm = new KPixmap(); - KVirtualBGRenderer *r = m_Renderer[desk]; - bool do_cleanup = true; - fadeDesk = desk; - mAlpha = 1.0; - int width,height; - - - *pm = r->pixmap(); - // If current: paint it - bool current = (r->hash() == m_Renderer[effectiveDesktop()]->hash()); - if (current) - { - //START - if (m_Renderer[effectiveDesktop()]->renderer(0)->crossFadeBg() && !m_Renderer[effectiveDesktop()]->renderer(0)->usingCrossXml() && !resizingDesktop) { - int mode = m_Renderer[effectiveDesktop()]->renderer(0)->wallpaperMode(); - width = TQApplication::desktop()->screenGeometry().width(); - height = TQApplication::desktop()->screenGeometry().height(); - - if (mode == KBackgroundSettings::NoWallpaper || mode == KBackgroundSettings::Tiled || mode == KBackgroundSettings::CenterTiled ){ - mNextScreen = TQPixmap(width,height); - TQPainter p (&mNextScreen); - p.drawTiledPixmap(0,0,width,height,*pm); - } else { - mNextScreen = TQPixmap(*pm); - } - - if (m_pDesktop){ - mOldScreen = const_cast( m_pDesktop->backgroundPixmap() ); - }else{ - mOldScreen = const_cast( - TQApplication::desktop()->screen()->backgroundPixmap() ); - } - - //TODO Find a way to discover if CrossFade effect needs to run - if (mOldScreen){ - crossInit = true; - m_crossTimer->start(70); - } else{ - setPixmap(pm, r->hash(), desk); - } - }else{ - setPixmap(pm, r->hash(), desk); - } - //ENDS HERE */ - - if (!m_bBgInitDone) - { - m_bBgInitDone = true; - emit initDone(); - TQTimer::singleShot( 30000, this, TQT_SLOT( saveImages())); - do_cleanup = false; - } - } - if (m_bExport || !m_bCommon) { - addCache(pm, r->hash(), desk); - } - else { - delete pm; - } - - if (current) { - exportBackground(desk, realDesktop()); - } - - if( do_cleanup ) { - r->saveCacheFile(); - r->cleanup(); - } - - resizingDesktop = false; -} - - -void KBackgroundManager::saveImages() -{ - for (unsigned i=0; isaveCacheFile(); - m_Renderer[i]->cleanup(); - } -} - -/* - * Size in bytes of a TQPixmap. For use in the pixmap cache. - */ -int KBackgroundManager::pixmapSize(TQPixmap *pm) -{ - return (pm->width() * pm->height()) * ((pm->depth() + 7) / 8); -} - - -/* - * Total size of the pixmap cache. - */ -int KBackgroundManager::cacheSize() -{ - int total = 0; - for (unsigned i=0; ipixmap) - total += pixmapSize(m_Cache[i]->pixmap); - } - return total; -} - - -/* - * Remove an entry from the pixmap cache. - */ -void KBackgroundManager::removeCache(int desk) -{ - if (m_bExport) - m_pPixmapServer->remove(KRootPixmap::pixmapName(desk+1)); - else - delete m_Cache[desk]->pixmap; - m_Cache[desk]->pixmap = 0L; - m_Cache[desk]->hash = 0; - m_Cache[desk]->exp_from = -1; - m_Cache[desk]->atime = 0; - - // Remove cache entries pointing to the removed entry - for (unsigned i=0; iexp_from == desk) - { - assert(m_bExport); - m_Cache[i]->exp_from = -1; - m_pPixmapServer->remove(KRootPixmap::pixmapName(i+1)); - } - } -} - - -/* - * Try to free up to size bytes from the cache. - */ -bool KBackgroundManager::freeCache(int size) -{ - if (m_bExport || !m_bLimitCache) - return true; - - // If it doesn't fit at all, return now. - if (size > m_CacheLimit) - return false; - - // If cache is too full, purge it (LRU) - while (size+cacheSize() > m_CacheLimit) - { - int j, min; - min = m_Serial+1; j = 0; - for (unsigned i=0; ipixmap && (m_Cache[i]->atime < min)) - { - min = m_Cache[i]->atime; - j = i; - } - } - removeCache(j); - } - return true; -} - - -/* - * Try to add a pixmap to the pixmap cache. We don't use TQPixmapCache here - * because if we're exporting pixmaps, this needs special care. - */ -void KBackgroundManager::addCache(KPixmap *pm, int hash, int desk) -{ - if (m_Cache[desk]->pixmap) - removeCache(desk); - - if (m_bLimitCache && !m_bExport && !freeCache(pixmapSize(pm))) - { - // pixmap does not fit in cache - delete pm; - return; - } - - m_Cache[desk]->pixmap = pm; - m_Cache[desk]->hash = hash; - m_Cache[desk]->atime = m_Serial; - m_Cache[desk]->exp_from = -1; - exportBackground(desk, desk); -} - -/* - * Called every minute to check if we need to rerun a background program. - * or change a wallpaper. - */ -void KBackgroundManager::slotTimeout() -{ - TQMemArray running(m_Renderer.size()); - running.fill(0); - - int NumDesks = m_Renderer.size(); - if (m_bCommon) - NumDesks = 1; - - int edesk = effectiveDesktop(); - - for (int i=0; ineedProgramUpdate()) - { - r->programUpdate(); - change = true; - } - - if (r->needWallpaperChange()) - { - r->changeWallpaper(); - change = true; - } - - if (change && (i == edesk)) - { - running[i] = r->hash(); - r->start(); - } - } -} - -// Return a valid desk number. -int KBackgroundManager::validateDesk(int desk) -{ - if (desk > (int)m_Renderer.size()) - slotChangeNumberOfDesktops( m_pKwinmodule->numberOfDesktops() ); - - if ( (desk <= 0) || (desk > (int)m_Renderer.size()) ) - return realDesktop(); - - return desk - 1; -} - -// DCOP exported -// Return current wallpaper for specified desk. -// 0 is for the current visible desktop. -TQString KBackgroundManager::currentWallpaper(int desk) -{ - //TODO Is the behaviour of this function appropriate for multiple screens? - KCrossBGRender *r = m_Renderer[validateDesk(desk)]->renderer(0); - - return r->currentWallpaper(); -} - -// DCOP exported -void KBackgroundManager::changeWallpaper() -{ - KVirtualBGRenderer *r = m_Renderer[effectiveDesktop()]; - - r->changeWallpaper(); - slotChangeDesktop(0); -} - -// DCOP exported -void KBackgroundManager::setExport(int _export) -{ -// kdDebug() << "KBackgroundManager enabling exports.\n"; - bool changed = (_export != m_bExport); - applyExport(_export); - if (changed) { - slotChangeDesktop(0); - } -} - -// DCOP exported -void KBackgroundManager::setCommon(int common) -{ - applyCommon(common); - KDesktopSettings::setCommonDesktop( m_bCommon ); - KDesktopSettings::writeConfig(); - slotChangeDesktop(0); -} - -// DCOP exported -void KBackgroundManager::setWallpaper(TQString wallpaper, int mode) -{ - if (mode < 0 || mode >= KBackgroundSettings::lastWallpaperMode) { - kdDebug() << "Invalid background mode " << mode << " passed to " << k_funcinfo << "\n"; - return; - } - - //TODO Is the behaviour of this function appropriate for multiple screens? - for (unsigned i=0; i < m_Renderer[effectiveDesktop()]->numRenderers(); ++i) - { - KCrossBGRender *r = m_Renderer[effectiveDesktop()]->renderer(i); - r->stop(); - r->setWallpaperMode(mode); - r->setMultiWallpaperMode(KBackgroundSettings::NoMulti); - r->setWallpaper(wallpaper); - r->writeSettings(); - } - slotChangeDesktop(0); -} - -void KBackgroundManager::setWallpaper(TQString wallpaper) -{ - //TODO Is the behaviour of this function appropriate for multiple screens? - KCrossBGRender *r = m_Renderer[effectiveDesktop()]->renderer(0); - int mode = r->wallpaperMode(); - if (mode == KBackgroundSettings::NoWallpaper) - mode = KBackgroundSettings::Tiled; - setWallpaper(wallpaper, mode); -} - -// DCOP exported -// Returns the filenames of all wallpaper entries for specified desk -// 0 is for current visible desktop. -TQStringList KBackgroundManager::wallpaperFiles(int desk) -{ - //TODO Is the behaviour of this function appropriate for multiple screens? - KCrossBGRender *r = m_Renderer[validateDesk(desk)]->renderer(0); - - return r->wallpaperFiles(); -} - -// DCOP exported -// Returns the list of wallpaper entries (viewable in background slide -// show window) for specified desk. 0 is for current visible desktop. -TQStringList KBackgroundManager::wallpaperList(int desk) -{ - //TODO Is the behaviour of this function appropriate for multiple screens? - KCrossBGRender *r = m_Renderer[validateDesk(desk)]->renderer(0);; - - return r->wallpaperList(); -} - -// DCOP exported -void KBackgroundManager::setCache( int bLimit, int size ) -{ - applyCache( bLimit, size*1024 ); - KDesktopSettings::setLimitCache( (bool) bLimit ); - KDesktopSettings::setCacheSize( size ); - KDesktopSettings::writeConfig(); -} - -// DCOP exported -void KBackgroundManager::setWallpaper(int desk, TQString wallpaper, int mode) -{ - if (mode < 0 || mode >= KBackgroundSettings::lastWallpaperMode) { - kdDebug() << "Invalid background mode " << mode << " passed to " << k_funcinfo << "\n"; - return; - } - - int sdesk = validateDesk(desk); - - //TODO Is the behaviour of this function appropriate for multiple screens? - for (unsigned i=0; i < m_Renderer[sdesk]->numRenderers(); ++i) - { - KCrossBGRender *r = m_Renderer[sdesk]->renderer(i); - - setCommon(false); // Force each desktop to have it's own wallpaper - - r->stop(); - r->setWallpaperMode(mode); - r->setMultiWallpaperMode(KBackgroundSettings::NoMulti); - r->setWallpaper(wallpaper); - r->writeSettings(); - } - slotChangeDesktop(sdesk); -} - -void KBackgroundManager::repaintBackground() -{ - if (m_pDesktop) - m_pDesktop->repaint(); - else - TQT_TQWIDGET(TDEApplication::desktop()->screen())->erase(); -} - -void KBackgroundManager::desktopResized() -{ - resizingDesktop = true; - for (unsigned i=0; iisActive()) - r->stop(); - removeCache(i); - // make the renderer update its desktop size - r->desktopResized(); - for (unsigned j=0; j<(r->numRenderers()); ++j) { - r->renderer(j)->desktopResized(); - } - } - -#ifdef COMPOSITE - if (m_tPixmap) - delete m_tPixmap; - m_tPixmap = new KPixmap(kapp->desktop()->size()); - m_tPixmap->fill(TQColor(0, 0x0)); -#endif - - m_Hash = 0; - if( m_pDesktop ) { - m_pDesktop->resize( kapp->desktop()->geometry().size()); - if (m_Renderer[effectiveDesktop()]->renderer(0)->usingCrossXml()){ - m_Renderer[effectiveDesktop()]->renderer(0)->changeWallpaper(); - } - } - // Repaint desktop - slotChangeDesktop(0); - repaintBackground(); - - // Redraw all desktops so that applications relying on exported data, e.g. kpager, continue to work properly - TQSize s(m_pKwinmodule->numberOfViewports(m_pKwinmodule->currentDesktop())); - m_numberOfViewports = s.width() * s.height(); - if (m_numberOfViewports < 1) { - m_numberOfViewports = 1; - } - for (signed j=0;j<(m_pKwinmodule->numberOfDesktops() * m_numberOfViewports);j++) { - renderBackground(j); - } -} - -// DCOP exported -void KBackgroundManager::setColor(const TQColor & c, bool isColorA) -{ - //TODO Is the behaviour of this function appropriate for multiple screens? - for (unsigned i=0; i < m_Renderer[effectiveDesktop()]->numRenderers(); ++i) - { - KCrossBGRender *r = m_Renderer[effectiveDesktop()]->renderer(i); - r->stop(); - - if (isColorA) - r->setColorA(c); - else - r->setColorB(c); - - int mode = r->backgroundMode(); - if (mode == KBackgroundSettings::Program) - mode = KBackgroundSettings::Flat; - - if (!isColorA && (mode == KBackgroundSettings::Flat)) - mode = KBackgroundSettings::VerticalGradient; - r->setBackgroundMode(mode); - - r->writeSettings(); - } - slotChangeDesktop(0); -} - -void KBackgroundManager::setBackgroundEnabled( const bool enable ) -{ - if (m_bEnabled == enable) - return; - - m_bEnabled= enable; - - int NumDesks = m_Renderer.size(); - if (m_bCommon) - NumDesks = 1; - - for (int i=0; isetEnabled(enable); - } - slotChangeDesktop(0); -} - -#ifdef COMPOSITE -void KBackgroundManager::slotCmBackgroundChanged( bool ) -{ - m_tPixmap->fill(TQColor(0, 0x0)); - m_Hash = 0; - slotChangeDesktop(0); -} -#endif - -#include "bgmanager.moc" diff --git a/kdesktop/bgmanager.cpp b/kdesktop/bgmanager.cpp new file mode 100644 index 000000000..7e90e8fca --- /dev/null +++ b/kdesktop/bgmanager.cpp @@ -0,0 +1,1109 @@ +/* + * + * This file is part of the KDE project, module kdesktop. + * Copyright (C) 1999,2000 Geert Jansen + * + * You can Freely distribute this program under the GNU General Public + * License. See the file "COPYING" for the exact licensing terms. + */ + +#include +#include "bgrender.h" +#include "bgmanager.h" +#include "bgdefaults.h" +#include "kdesktopsettings.h" +#include "bgsettings.h" +#include "kdesktopapp.h" + +#include "KCrossBGRender.h" +#include "crossfade.h" + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifndef None +#define None 0L +#endif + +#ifdef COMPOSITE +# include +# include +# include +#endif + +#include "pixmapserver.h" + +template class TQPtrVector; +template class TQPtrVector; +template class TQMemArray; + +static Atom prop_root; +static bool properties_inited = false; + +extern bool argb_visual; +extern KDesktopApp *myApp; + +/**** KBackgroundManager ****/ + +KBackgroundManager::KBackgroundManager(TQWidget *desktop, KWinModule* twinModule) + : KBackgroundIface() +{ + if( !properties_inited ) + { + prop_root = XInternAtom(tqt_xdisplay(), "_XROOTPMAP_ID", False); + properties_inited = true; + } + m_bBgInitDone = false; + m_bEnabled = true; + + m_pDesktop = desktop; + if (desktop == 0L) + desktop = TQT_TQWIDGET(TDEApplication::desktop()->screen()); + + m_Renderer.resize( 1 ); + m_Cache.resize( 1 ); + + m_Serial = 0; m_Hash = 0; + m_pConfig = TDEGlobal::config(); + m_bExport = m_bCommon = m_bInit = false; + m_pKwinmodule = twinModule; + m_pPixmapServer = new KPixmapServer(); + m_xrootpmap = None; + + for (unsigned i=0; ipixmap = 0L; + m_Cache[i]->hash = 0; + m_Cache[i]->exp_from = -1; + m_Renderer.insert (i, new KVirtualBGRenderer(i,m_pConfig)); + connect(m_Renderer[i], TQT_SIGNAL(imageDone(int)), TQT_SLOT(slotImageDone(int))); + m_Renderer[i]->enableTiling( true ); // optimize + } + +#ifdef COMPOSITE + m_tPixmap = new KPixmap(kapp->desktop()->size()); + m_tPixmap->fill(TQColor(0, 0x0)); + connect(myApp, TQT_SIGNAL(cmBackgroundChanged( bool )), + TQT_SLOT(slotCmBackgroundChanged( bool ))); +#endif + + configure(); + + m_pTimer = new TQTimer(this); + connect(m_pTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotTimeout())); + m_pTimer->start( 60000 ); + + /*CrossFade's config*/ + m_crossTimer = new TQTimer(this); + connect(m_crossTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotCrossFadeTimeout())); + resizingDesktop = true; + /*Ends here*/ + + + connect(m_pKwinmodule, TQT_SIGNAL(currentDesktopChanged(int)), + TQT_SLOT(slotChangeDesktop(int))); + connect(m_pKwinmodule, TQT_SIGNAL(numberOfDesktopsChanged(int)), + TQT_SLOT(slotChangeNumberOfDesktops(int))); + connect(m_pKwinmodule, TQT_SIGNAL(currentDesktopViewportChanged(int, const TQPoint&)), + TQT_SLOT(slotChangeViewport(int, const TQPoint&))); + + +#if (TQT_VERSION-0 >= 0x030200) + connect( kapp->desktop(), TQT_SIGNAL( resized( int )), TQT_SLOT( desktopResized())); // RANDR support +#endif + + TQSize s(m_pKwinmodule->numberOfViewports(m_pKwinmodule->currentDesktop())); + m_numberOfViewports = s.width() * s.height(); + if (m_numberOfViewports < 1) { + m_numberOfViewports = 1; + } + for (signed j=0;j<(m_pKwinmodule->numberOfDesktops() * m_numberOfViewports);j++) { + renderBackground(j); + } +} + + +KBackgroundManager::~KBackgroundManager() +{ + for (unsigned i=0; ipixmap; + delete m_Cache[i]; + } +} + + +void KBackgroundManager::applyExport(bool exp) +{ + if (exp == m_bExport) + return; + + // If export mode changed from true -> false, remove all shared pixmaps. + // If it changed false -> true force a redraw because the current screen + // image might not have an associated pixmap in the cache. + if (!exp) + { + for (unsigned i=0; i true, remove all cache entries, except + // at index 0 if exports are on. + if (m_bCommon) + { + if (!m_bExport) + removeCache(0); + for (unsigned i=1; ireparseConfiguration(); + KDesktopSettings::self()->readConfig(); + + // Read individual settings + KVirtualBGRenderer *r; + for (unsigned i=0; ihash(); + r->load(i,false); + if ((r->hash() != ohash)) + removeCache(i); + } + + applyCommon(KDesktopSettings::commonDesktop()); + + bool limit = KDesktopSettings::limitCache(); + int size = KDesktopSettings::cacheSize() * 1024; + applyCache(limit, size); + + // Repaint desktop + slotChangeDesktop(0); + + // Redraw all desktops so that applications relying on exported data, e.g. kpager, continue to work properly + TQSize s(m_pKwinmodule->numberOfViewports(m_pKwinmodule->currentDesktop())); + m_numberOfViewports = s.width() * s.height(); + if (m_numberOfViewports < 1) { + m_numberOfViewports = 1; + } + for (signed j=0;j<(m_pKwinmodule->numberOfDesktops() * m_numberOfViewports);j++) { + renderBackground(j); + } +} + + +int KBackgroundManager::realDesktop() +{ + int desk = m_pKwinmodule->currentDesktop(); + if (desk) desk--; + return desk; +} + + +int KBackgroundManager::effectiveDesktop() +{ + TQSize s(m_pKwinmodule->numberOfViewports(m_pKwinmodule->currentDesktop())); + m_numberOfViewports = s.width() * s.height(); + + if (m_numberOfViewports > 1) { + if (m_bCommon) { + return 0; + } + else { + TQPoint vx(m_pKwinmodule->currentViewport(m_pKwinmodule->currentDesktop())); + return (realDesktop() * m_numberOfViewports) + ((vx.x() * vx.y()) - 1); + } + } + else { + return m_bCommon ? 0 : realDesktop(); + } +} + + +/* + * Number of desktops changed + */ +void KBackgroundManager::slotChangeNumberOfDesktops(int num) +{ + TQSize s(m_pKwinmodule->numberOfViewports(m_pKwinmodule->currentDesktop())); + m_numberOfViewports = s.width() * s.height(); + if (m_numberOfViewports < 1) { + m_numberOfViewports = 1; + } + num = (num * m_numberOfViewports); + + if (m_Renderer.size() == (unsigned) num) + return; + + if (m_Renderer.size() > (unsigned) num) + { + for (unsigned i=num; iisActive()) + m_Renderer[i]->stop(); + delete m_Renderer[i]; + removeCache(i); + } + for (unsigned i=num; ipixmap = 0L; + m_Cache[i]->hash = 0; + m_Cache[i]->exp_from = -1; + m_Renderer.insert(i, new KVirtualBGRenderer(i,m_pConfig)); + connect(m_Renderer[i], TQT_SIGNAL(imageDone(int)), TQT_SLOT(slotImageDone(int))); + m_Renderer[i]->enableTiling( true ); // optimize + } + } +} + +/* + * Call this when the desktop has been changed. + * Desk is in KWin convention: [1..desks], instead of [0..desks-1]. + * 0 repaints the current desktop. + */ +void KBackgroundManager::slotChangeDesktop(int desk) +{ + resizingDesktop = true; + TQSize s(m_pKwinmodule->numberOfViewports(m_pKwinmodule->currentDesktop())); + m_numberOfViewports = s.width() * s.height(); + if (m_numberOfViewports < 1) { + m_numberOfViewports = 1; + } + + if (desk == 0) + desk = realDesktop(); + else + desk--; + + // Lazy initialisation of # of desktops + if ((unsigned)(m_pKwinmodule->numberOfDesktops() * m_numberOfViewports) >= m_Renderer.size()) + slotChangeNumberOfDesktops( m_pKwinmodule->numberOfDesktops() * m_numberOfViewports); + + int edesk = effectiveDesktop(); + m_Serial++; + + // If the background is the same: do nothing + if ((m_Hash == m_Renderer[edesk]->hash()) && (desk != 0)) + { + exportBackground(m_Current, desk); + return; + } + m_Renderer[edesk]->stop(); + m_Renderer[edesk]->cleanup(); + + // If we have the background already rendered: set it + for (unsigned i=0; ipixmap) + continue; + if (m_Cache[i]->hash != m_Renderer[edesk]->hash()) + continue; + if (desk == 0) + continue; +// kdDebug() << "slotChangeDesktop i=" << i << endl; + setPixmap(m_Cache[i]->pixmap, m_Cache[i]->hash, i); + m_Cache[i]->atime = m_Serial; + exportBackground(i, desk); + return; + } + + // Do we have this or an identical config already running? + for (unsigned i=0; ihash() == m_Renderer[edesk]->hash()) && (m_Renderer[i]->isActive())) && (desk != 0)) { + return; + } + } + + renderBackground(edesk); +} + +/* + * Call this when the viewport has been changed. + * Desk is in KWin convention: [1..desks], instead of [0..desks-1]. + * 0 repaints the current viewport. + */ +void KBackgroundManager::slotChangeViewport(int desk, const TQPoint& viewport) +{ + TQSize s(m_pKwinmodule->numberOfViewports(m_pKwinmodule->currentDesktop())); + m_numberOfViewports = s.width() * s.height(); + if (m_numberOfViewports < 1) { + m_numberOfViewports = 1; + } + + if (desk == 0) + desk = realDesktop(); + else + desk--; + + // Lazy initialisation of # of desktops + if ((unsigned)(m_pKwinmodule->numberOfDesktops() * m_numberOfViewports) >= m_Renderer.size()) + slotChangeNumberOfDesktops( m_pKwinmodule->numberOfDesktops() * m_numberOfViewports ); + + int edesk = effectiveDesktop(); + m_Serial++; + + // If the background is the same: do nothing + if ((m_Hash == m_Renderer[edesk]->hash()) && (desk != 0)) + { + exportBackground(m_Current, desk); + return; + } + m_Renderer[edesk]->stop(); + m_Renderer[edesk]->cleanup(); + + // If we have the background already rendered: set it + for (unsigned i=0; ipixmap) + continue; + if (m_Cache[i]->hash != m_Renderer[edesk]->hash()) + continue; + if (desk == 0) + continue; +// kdDebug() << "slotChangeDesktop i=" << i << endl; + + //KPixmap * viewport_background = new KPixmap(TQPixmap(m_Cache[i]->pixmap->width()*s.width(), m_Cache[i]->pixmap->height()*s.height())); + //setPixmap(viewport_background, m_Cache[i]->hash, i); + //delete viewport_background; + + setPixmap(m_Cache[i]->pixmap, m_Cache[i]->hash, i); + m_Cache[i]->atime = m_Serial; + exportBackground(i, desk); + return; + } + + // Do we have this or an identical config already running? + for (unsigned i=0; ihash() == m_Renderer[edesk]->hash()) && (m_Renderer[i]->isActive())) && (desk != 0)) + return; + } + + renderBackground(edesk); +} + + +/* + * Share a desktop pixmap. + */ +void KBackgroundManager::exportBackground(int pixmap, int desk) +{ + if (!m_bExport || (m_Cache[desk]->exp_from == pixmap)) + return; + + m_Cache[desk]->exp_from = pixmap; + m_pPixmapServer->add(KRootPixmap::pixmapName(desk+1), + m_Cache[pixmap]->pixmap); + KIPC::sendMessageAll(KIPC::BackgroundChanged, desk+1); +} + + +/* + * Paint the pixmap to the root window. + */ +void KBackgroundManager::setPixmap(KPixmap *pm, int hash, int desk) +{ + KPixmap *ep = pm; + +#ifdef COMPOSITE + if (argb_visual && (KDesktopSettings::backgroundOpacity() < 100 + || myApp->cmBackground())) + { + ep = m_tPixmap; + if (KDesktopSettings::backgroundOpacity() > 0 && pm + && !myApp->cmBackground()) + { + XRenderPictFormat *format; + format = XRenderFindStandardFormat (tqt_xdisplay(), PictStandardARGB32); + + XRenderColor fillColor; + + int color = KDesktopSettings::backgroundOpacity() * 0xffff / 100; + fillColor.red = color; + fillColor.green = color; + fillColor.blue = color; + fillColor.alpha = color; + + Picture fill = XRenderCreateSolidFill (tqt_xdisplay(), &fillColor); + Picture src = XRenderCreatePicture(tqt_xdisplay(), pm->handle(), + format, 0, NULL); + Picture dst = XRenderCreatePicture(tqt_xdisplay(), ep->handle(), + format, 0, NULL); + + XRenderComposite (tqt_xdisplay(), PictOpSrc, src, fill, dst, 0, 0, 0, + 0, 0, 0, pm->width(), pm->height()); + + XRenderFreePicture (tqt_xdisplay(), fill); + XRenderFreePicture (tqt_xdisplay(), src); + XRenderFreePicture (tqt_xdisplay(), dst); + } + } +#endif + + if (m_pDesktop) + { + TQScrollView* sv = dynamic_cast( m_pDesktop ); + if ( sv ) { + // Qt eats repaint events in this case :-(( + sv->viewport()->update(); + } + m_pDesktop->setErasePixmap(*ep); + m_pDesktop->repaint(); + static bool root_cleared = false; + if( !root_cleared ) + { // clear the root window pixmap set by tdm + root_cleared = true; + TQTimer::singleShot( 0, this, TQT_SLOT( clearRoot())); + // but make the pixmap visible until m_pDesktop is visible + TQT_TQWIDGET(TDEApplication::desktop()->screen())->setErasePixmap(*ep); + TQT_TQWIDGET(TDEApplication::desktop()->screen())->erase(); + } + } + else + { + TQT_TQWIDGET(TDEApplication::desktop()->screen())->setErasePixmap(*ep); + TQT_TQWIDGET(TDEApplication::desktop()->screen())->erase(); + } + + // and export it via Esetroot-style for gnome/GTK apps to share in the pretties + Pixmap bgPm = pm->handle(); // fetch the actual X handle to it + //kdDebug() << "Esetroot compat: setting pixmap to " << bgPm << endl; + + // don't set the ESETROOT_PMAP_ID property - that would result in possible XKillClient() + // done on kdesktop + + XChangeProperty(tqt_xdisplay(), tqt_xrootwin(), prop_root, XA_PIXMAP, 32, PropModeReplace, + (unsigned char *) &bgPm, 1); + m_xrootpmap = bgPm; + + m_Hash = hash; + m_Current = desk; +} + +void KBackgroundManager::clearRoot() +{ + TQT_TQWIDGET(TDEApplication::desktop()->screen())->setErasePixmap( TQPixmap()); + TQT_TQWIDGET(TDEApplication::desktop()->screen())->erase(); +} + +/* + * Start the render of a desktop background. + */ +void KBackgroundManager::renderBackground(int desk) +{ + KVirtualBGRenderer *r = m_Renderer[desk]; + if (r->isActive()) + { + kdDebug() << "renderer " << desk << " already active" << endl; + return; + } + + r->start(); +} + + +/* + * This slot is called when the Timeout is executed + */ +void KBackgroundManager::slotCrossFadeTimeout() +{ + KVirtualBGRenderer *r = m_Renderer[fadeDesk]; + if (crossInit) { + mBenchmark.start(); + } + + if (mAlpha <= 0.0 || mBenchmark.elapsed() > 300 ) { + mAlpha = 1; + m_crossTimer->stop(); + KPixmap pixm(mNextScreen); + setPixmap(&pixm, r->hash(), fadeDesk); + return; + } + // Reset Timer + mBenchmark.start(); + + TQPixmap dst = crossFade(*mOldScreen, mNextScreen, mAlpha, crossInit); + KPixmap pixm(dst); + setPixmap(&pixm, r->hash(), fadeDesk); + + mAlpha -=0.03; + crossInit = false; +} + + +/* + * This slot is called when a renderer is done. + */ +void KBackgroundManager::slotImageDone(int desk) +{ + TQSize s(m_pKwinmodule->numberOfViewports(m_pKwinmodule->currentDesktop())); + m_numberOfViewports = s.width() * s.height(); + if (m_numberOfViewports < 1) { + m_numberOfViewports = 1; + } + + KPixmap *pm = new KPixmap(); + KVirtualBGRenderer *r = m_Renderer[desk]; + bool do_cleanup = true; + fadeDesk = desk; + mAlpha = 1.0; + int width,height; + + + *pm = r->pixmap(); + // If current: paint it + bool current = (r->hash() == m_Renderer[effectiveDesktop()]->hash()); + if (current) + { + //START + if (m_Renderer[effectiveDesktop()]->renderer(0)->crossFadeBg() && !m_Renderer[effectiveDesktop()]->renderer(0)->usingCrossXml() && !resizingDesktop) { + int mode = m_Renderer[effectiveDesktop()]->renderer(0)->wallpaperMode(); + width = TQApplication::desktop()->screenGeometry().width(); + height = TQApplication::desktop()->screenGeometry().height(); + + if (mode == KBackgroundSettings::NoWallpaper || mode == KBackgroundSettings::Tiled || mode == KBackgroundSettings::CenterTiled ){ + mNextScreen = TQPixmap(width,height); + TQPainter p (&mNextScreen); + p.drawTiledPixmap(0,0,width,height,*pm); + } else { + mNextScreen = TQPixmap(*pm); + } + + if (m_pDesktop){ + mOldScreen = const_cast( m_pDesktop->backgroundPixmap() ); + }else{ + mOldScreen = const_cast( + TQApplication::desktop()->screen()->backgroundPixmap() ); + } + + //TODO Find a way to discover if CrossFade effect needs to run + if (mOldScreen){ + crossInit = true; + m_crossTimer->start(70); + } else{ + setPixmap(pm, r->hash(), desk); + } + }else{ + setPixmap(pm, r->hash(), desk); + } + //ENDS HERE */ + + if (!m_bBgInitDone) + { + m_bBgInitDone = true; + emit initDone(); + TQTimer::singleShot( 30000, this, TQT_SLOT( saveImages())); + do_cleanup = false; + } + } + if (m_bExport || !m_bCommon) { + addCache(pm, r->hash(), desk); + } + else { + delete pm; + } + + if (current) { + exportBackground(desk, realDesktop()); + } + + if( do_cleanup ) { + r->saveCacheFile(); + r->cleanup(); + } + + resizingDesktop = false; +} + + +void KBackgroundManager::saveImages() +{ + for (unsigned i=0; isaveCacheFile(); + m_Renderer[i]->cleanup(); + } +} + +/* + * Size in bytes of a TQPixmap. For use in the pixmap cache. + */ +int KBackgroundManager::pixmapSize(TQPixmap *pm) +{ + return (pm->width() * pm->height()) * ((pm->depth() + 7) / 8); +} + + +/* + * Total size of the pixmap cache. + */ +int KBackgroundManager::cacheSize() +{ + int total = 0; + for (unsigned i=0; ipixmap) + total += pixmapSize(m_Cache[i]->pixmap); + } + return total; +} + + +/* + * Remove an entry from the pixmap cache. + */ +void KBackgroundManager::removeCache(int desk) +{ + if (m_bExport) + m_pPixmapServer->remove(KRootPixmap::pixmapName(desk+1)); + else + delete m_Cache[desk]->pixmap; + m_Cache[desk]->pixmap = 0L; + m_Cache[desk]->hash = 0; + m_Cache[desk]->exp_from = -1; + m_Cache[desk]->atime = 0; + + // Remove cache entries pointing to the removed entry + for (unsigned i=0; iexp_from == desk) + { + assert(m_bExport); + m_Cache[i]->exp_from = -1; + m_pPixmapServer->remove(KRootPixmap::pixmapName(i+1)); + } + } +} + + +/* + * Try to free up to size bytes from the cache. + */ +bool KBackgroundManager::freeCache(int size) +{ + if (m_bExport || !m_bLimitCache) + return true; + + // If it doesn't fit at all, return now. + if (size > m_CacheLimit) + return false; + + // If cache is too full, purge it (LRU) + while (size+cacheSize() > m_CacheLimit) + { + int j, min; + min = m_Serial+1; j = 0; + for (unsigned i=0; ipixmap && (m_Cache[i]->atime < min)) + { + min = m_Cache[i]->atime; + j = i; + } + } + removeCache(j); + } + return true; +} + + +/* + * Try to add a pixmap to the pixmap cache. We don't use TQPixmapCache here + * because if we're exporting pixmaps, this needs special care. + */ +void KBackgroundManager::addCache(KPixmap *pm, int hash, int desk) +{ + if (m_Cache[desk]->pixmap) + removeCache(desk); + + if (m_bLimitCache && !m_bExport && !freeCache(pixmapSize(pm))) + { + // pixmap does not fit in cache + delete pm; + return; + } + + m_Cache[desk]->pixmap = pm; + m_Cache[desk]->hash = hash; + m_Cache[desk]->atime = m_Serial; + m_Cache[desk]->exp_from = -1; + exportBackground(desk, desk); +} + +/* + * Called every minute to check if we need to rerun a background program. + * or change a wallpaper. + */ +void KBackgroundManager::slotTimeout() +{ + TQMemArray running(m_Renderer.size()); + running.fill(0); + + int NumDesks = m_Renderer.size(); + if (m_bCommon) + NumDesks = 1; + + int edesk = effectiveDesktop(); + + for (int i=0; ineedProgramUpdate()) + { + r->programUpdate(); + change = true; + } + + if (r->needWallpaperChange()) + { + r->changeWallpaper(); + change = true; + } + + if (change && (i == edesk)) + { + running[i] = r->hash(); + r->start(); + } + } +} + +// Return a valid desk number. +int KBackgroundManager::validateDesk(int desk) +{ + if (desk > (int)m_Renderer.size()) + slotChangeNumberOfDesktops( m_pKwinmodule->numberOfDesktops() ); + + if ( (desk <= 0) || (desk > (int)m_Renderer.size()) ) + return realDesktop(); + + return desk - 1; +} + +// DCOP exported +// Return current wallpaper for specified desk. +// 0 is for the current visible desktop. +TQString KBackgroundManager::currentWallpaper(int desk) +{ + //TODO Is the behaviour of this function appropriate for multiple screens? + KCrossBGRender *r = m_Renderer[validateDesk(desk)]->renderer(0); + + return r->currentWallpaper(); +} + +// DCOP exported +void KBackgroundManager::changeWallpaper() +{ + KVirtualBGRenderer *r = m_Renderer[effectiveDesktop()]; + + r->changeWallpaper(); + slotChangeDesktop(0); +} + +// DCOP exported +void KBackgroundManager::setExport(int _export) +{ +// kdDebug() << "KBackgroundManager enabling exports.\n"; + bool changed = (_export != m_bExport); + applyExport(_export); + if (changed) { + slotChangeDesktop(0); + } +} + +// DCOP exported +void KBackgroundManager::setCommon(int common) +{ + applyCommon(common); + KDesktopSettings::setCommonDesktop( m_bCommon ); + KDesktopSettings::writeConfig(); + slotChangeDesktop(0); +} + +// DCOP exported +void KBackgroundManager::setWallpaper(TQString wallpaper, int mode) +{ + if (mode < 0 || mode >= KBackgroundSettings::lastWallpaperMode) { + kdDebug() << "Invalid background mode " << mode << " passed to " << k_funcinfo << "\n"; + return; + } + + //TODO Is the behaviour of this function appropriate for multiple screens? + for (unsigned i=0; i < m_Renderer[effectiveDesktop()]->numRenderers(); ++i) + { + KCrossBGRender *r = m_Renderer[effectiveDesktop()]->renderer(i); + r->stop(); + r->setWallpaperMode(mode); + r->setMultiWallpaperMode(KBackgroundSettings::NoMulti); + r->setWallpaper(wallpaper); + r->writeSettings(); + } + slotChangeDesktop(0); +} + +void KBackgroundManager::setWallpaper(TQString wallpaper) +{ + //TODO Is the behaviour of this function appropriate for multiple screens? + KCrossBGRender *r = m_Renderer[effectiveDesktop()]->renderer(0); + int mode = r->wallpaperMode(); + if (mode == KBackgroundSettings::NoWallpaper) + mode = KBackgroundSettings::Tiled; + setWallpaper(wallpaper, mode); +} + +// DCOP exported +// Returns the filenames of all wallpaper entries for specified desk +// 0 is for current visible desktop. +TQStringList KBackgroundManager::wallpaperFiles(int desk) +{ + //TODO Is the behaviour of this function appropriate for multiple screens? + KCrossBGRender *r = m_Renderer[validateDesk(desk)]->renderer(0); + + return r->wallpaperFiles(); +} + +// DCOP exported +// Returns the list of wallpaper entries (viewable in background slide +// show window) for specified desk. 0 is for current visible desktop. +TQStringList KBackgroundManager::wallpaperList(int desk) +{ + //TODO Is the behaviour of this function appropriate for multiple screens? + KCrossBGRender *r = m_Renderer[validateDesk(desk)]->renderer(0);; + + return r->wallpaperList(); +} + +// DCOP exported +void KBackgroundManager::setCache( int bLimit, int size ) +{ + applyCache( bLimit, size*1024 ); + KDesktopSettings::setLimitCache( (bool) bLimit ); + KDesktopSettings::setCacheSize( size ); + KDesktopSettings::writeConfig(); +} + +// DCOP exported +void KBackgroundManager::setWallpaper(int desk, TQString wallpaper, int mode) +{ + if (mode < 0 || mode >= KBackgroundSettings::lastWallpaperMode) { + kdDebug() << "Invalid background mode " << mode << " passed to " << k_funcinfo << "\n"; + return; + } + + int sdesk = validateDesk(desk); + + //TODO Is the behaviour of this function appropriate for multiple screens? + for (unsigned i=0; i < m_Renderer[sdesk]->numRenderers(); ++i) + { + KCrossBGRender *r = m_Renderer[sdesk]->renderer(i); + + setCommon(false); // Force each desktop to have it's own wallpaper + + r->stop(); + r->setWallpaperMode(mode); + r->setMultiWallpaperMode(KBackgroundSettings::NoMulti); + r->setWallpaper(wallpaper); + r->writeSettings(); + } + slotChangeDesktop(sdesk); +} + +void KBackgroundManager::repaintBackground() +{ + if (m_pDesktop) + m_pDesktop->repaint(); + else + TQT_TQWIDGET(TDEApplication::desktop()->screen())->erase(); +} + +void KBackgroundManager::desktopResized() +{ + resizingDesktop = true; + for (unsigned i=0; iisActive()) + r->stop(); + removeCache(i); + // make the renderer update its desktop size + r->desktopResized(); + for (unsigned j=0; j<(r->numRenderers()); ++j) { + r->renderer(j)->desktopResized(); + } + } + +#ifdef COMPOSITE + if (m_tPixmap) + delete m_tPixmap; + m_tPixmap = new KPixmap(kapp->desktop()->size()); + m_tPixmap->fill(TQColor(0, 0x0)); +#endif + + m_Hash = 0; + if( m_pDesktop ) { + m_pDesktop->resize( kapp->desktop()->geometry().size()); + if (m_Renderer[effectiveDesktop()]->renderer(0)->usingCrossXml()){ + m_Renderer[effectiveDesktop()]->renderer(0)->changeWallpaper(); + } + } + // Repaint desktop + slotChangeDesktop(0); + repaintBackground(); + + // Redraw all desktops so that applications relying on exported data, e.g. kpager, continue to work properly + TQSize s(m_pKwinmodule->numberOfViewports(m_pKwinmodule->currentDesktop())); + m_numberOfViewports = s.width() * s.height(); + if (m_numberOfViewports < 1) { + m_numberOfViewports = 1; + } + for (signed j=0;j<(m_pKwinmodule->numberOfDesktops() * m_numberOfViewports);j++) { + renderBackground(j); + } +} + +// DCOP exported +void KBackgroundManager::setColor(const TQColor & c, bool isColorA) +{ + //TODO Is the behaviour of this function appropriate for multiple screens? + for (unsigned i=0; i < m_Renderer[effectiveDesktop()]->numRenderers(); ++i) + { + KCrossBGRender *r = m_Renderer[effectiveDesktop()]->renderer(i); + r->stop(); + + if (isColorA) + r->setColorA(c); + else + r->setColorB(c); + + int mode = r->backgroundMode(); + if (mode == KBackgroundSettings::Program) + mode = KBackgroundSettings::Flat; + + if (!isColorA && (mode == KBackgroundSettings::Flat)) + mode = KBackgroundSettings::VerticalGradient; + r->setBackgroundMode(mode); + + r->writeSettings(); + } + slotChangeDesktop(0); +} + +void KBackgroundManager::setBackgroundEnabled( const bool enable ) +{ + if (m_bEnabled == enable) + return; + + m_bEnabled= enable; + + int NumDesks = m_Renderer.size(); + if (m_bCommon) + NumDesks = 1; + + for (int i=0; isetEnabled(enable); + } + slotChangeDesktop(0); +} + +#ifdef COMPOSITE +void KBackgroundManager::slotCmBackgroundChanged( bool ) +{ + m_tPixmap->fill(TQColor(0, 0x0)); + m_Hash = 0; + slotChangeDesktop(0); +} +#endif + +#include "bgmanager.moc" diff --git a/kdesktop/desktop.cc b/kdesktop/desktop.cc deleted file mode 100644 index 2732bff08..000000000 --- a/kdesktop/desktop.cc +++ /dev/null @@ -1,1197 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 1998, 1999 Torben Weis - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - - -#include "desktop.h" -#include "krootwm.h" -#include "bgmanager.h" -#include "bgsettings.h" -#include "startupid.h" -#include "kdiconview.h" -#include "minicli.h" -#include "kdesktopsettings.h" -#include "tdelaunchsettings.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 -#include -// Create the equivalent of TDEAccelBase::connectItem -// and then remove this include and fix reconnects in initRoot() -- ellis -//#include - -extern int kdesktop_screen_number; -extern TQCString kdesktop_name, kicker_name, twin_name; - -KRootWidget::KRootWidget() : TQObject() -{ - kapp->desktop()->installEventFilter(this); - kapp->desktop()->setAcceptDrops( true ); -} - -bool KRootWidget::eventFilter ( TQObject *, TQEvent * e ) -{ - if (e->type() == TQEvent::MouseButtonPress) - { - TQMouseEvent *me = TQT_TQMOUSEEVENT(e); - KRootWm::self()->mousePressed( me->globalPos(), me->button() ); - return true; - } - else if (e->type() == TQEvent::Wheel) - { - TQWheelEvent *we = TQT_TQWHEELEVENT(e); - emit wheelRolled(we->delta()); - return true; - } - else if ( e->type() == TQEvent::DragEnter ) - { - TQDragEnterEvent* de = static_cast( e ); - bool b = !TDEGlobal::config()->isImmutable() && !TDEGlobal::dirs()->isRestrictedResource( "wallpaper" ); - - bool imageURL = false; - if ( KURLDrag::canDecode( de ) ) - { - KURL::List list; - KURLDrag::decode( de, list ); - KURL url = list.first(); - KMimeType::Ptr mime = KMimeType::findByURL( url ); - if ( !KImageIO::type( url.path() ).isEmpty() || - KImageIO::isSupported( mime->name(), KImageIO::Reading ) || mime->is( "image/svg+xml" ) ) - imageURL = true; - } - - b = b && ( KColorDrag::canDecode( de ) || TQImageDrag::canDecode( de ) || imageURL ); - de->accept( b ); - return true; - } - else if ( e->type() == TQEvent::Drop ) - { - TQDropEvent* de = static_cast( e ); - if ( KColorDrag::canDecode( de ) ) - emit colorDropEvent( de ); - else if ( TQImageDrag::canDecode( de ) ) - emit imageDropEvent( de ); - else if ( KURLDrag::canDecode( de ) ) { - KURL::List list; - KURLDrag::decode( de, list ); - KURL url = list.first(); - emit newWallpaper( url ); - } - return true; - } - return false; // Don't filter. -} - -// ----------------------------------------------------------------------------- -#define DEFAULT_DELETEACTION 1 - -KDesktop::WheelDirection KDesktop::m_eWheelDirection = KDesktop::m_eDefaultWheelDirection; -const char* KDesktop::m_wheelDirectionStrings[2] = { "Forward", "Reverse" }; - -KDesktop::KDesktop( SaverEngine* saver, bool x_root_hack, bool wait_for_kded ) : - TQWidget( 0L, "desktop", (WFlags)(WResizeNoErase | ( x_root_hack ? (WStyle_Customize | WStyle_NoBorder) : 0)) ), - KDesktopIface(), - // those two WStyle_ break kdesktop when the root-hack isn't used (no Dnd) - startup_id( NULL ), m_waitForKicker(0) -{ - m_pSaver = saver; - - NETRootInfo i( tqt_xdisplay(), NET::Supported ); - m_wmSupport = i.isSupported( NET::WM2ShowingDesktop ); - - m_bWaitForKded = wait_for_kded; - m_miniCli = 0; // created on demand - keys = 0; // created later - TDEGlobal::locale()->insertCatalogue("kdesktop"); - TDEGlobal::locale()->insertCatalogue("libkonq"); // needed for apps using libkonq - TDEGlobal::locale()->insertCatalogue("libdmctl"); - - setCaption( "KDE Desktop"); - - setAcceptDrops(true); // WStyle_Customize seems to disable that - m_pKwinmodule = new KWinModule( TQT_TQOBJECT(this) ); - - kapp->dcopClient()->setNotifications(true); - kapp->dcopClient()->connectDCOPSignal(kicker_name, kicker_name, "desktopIconsAreaChanged(TQRect, int)", - "KDesktopIface", "desktopIconsAreaChanged(TQRect, int)", false); - - // Dont repaint on configuration changes during construction - m_bInit = true; - - // It's the child widget that gets the focus, not us - setFocusPolicy( TQ_NoFocus ); - - if ( x_root_hack ) - { - // this is a ugly hack to make Dnd work - // Matthias told me that it won't be necessary with twin - // actually my first try with ICCCM (Dirk) :-) - unsigned long data[2]; - data[0] = (unsigned long) 1; - data[1] = (unsigned long) 0; // None; (Werner) - Atom wm_state = XInternAtom(tqt_xdisplay(), "WM_STATE", False); - XChangeProperty(tqt_xdisplay(), winId(), wm_state, wm_state, 32, - PropModeReplace, (unsigned char *)data, 2); - - } - - setGeometry( TQApplication::desktop()->geometry() ); - lower(); - - connect( kapp, TQT_SIGNAL( shutDown() ), - this, TQT_SLOT( slotShutdown() ) ); - - connect(kapp, TQT_SIGNAL(settingsChanged(int)), - this, TQT_SLOT(slotSettingsChanged(int))); - kapp->addKipcEventMask(KIPC::SettingsChanged); - - kapp->addKipcEventMask(KIPC::IconChanged); - connect(kapp, TQT_SIGNAL(iconChanged(int)), this, TQT_SLOT(slotIconChanged(int))); - - connect(KSycoca::self(), TQT_SIGNAL(databaseChanged()), - this, TQT_SLOT(slotDatabaseChanged())); - - m_pIconView = 0; - m_pRootWidget = 0; - bgMgr = 0; - initRoot(); - - TQTimer::singleShot(0, this, TQT_SLOT( slotStart() )); - -#if (TQT_VERSION-0 >= 0x030200) // XRANDR support - connect( kapp->desktop(), TQT_SIGNAL( resized( int )), TQT_SLOT( desktopResized())); -#endif -} - -void -KDesktop::initRoot() -{ - Display *dpy = tqt_xdisplay(); - Window root = RootWindow(dpy, kdesktop_screen_number); - XDefineCursor(dpy, root, cursor().handle()); - - m_bDesktopEnabled = KDesktopSettings::desktopEnabled(); - if ( !m_bDesktopEnabled && !m_pRootWidget ) - { - hide(); - delete bgMgr; - bgMgr = 0; - if ( m_pIconView ) - m_pIconView->saveIconPositions(); - delete m_pIconView; - m_pIconView = 0; - - { // trigger creation of QToolTipManager, it does XSelectInput() on the root window - TQWidget w; - TQToolTip::add( &w, "foo" ); - } - // NOTE: If mouse clicks stop working again, it's most probably something doing XSelectInput() - // on the root window after this, and setting it to some fixed value instead of adding its mask. - XWindowAttributes attrs; - XGetWindowAttributes(dpy, root, &attrs); - XSelectInput(dpy, root, attrs.your_event_mask | ButtonPressMask); - - m_pRootWidget = new KRootWidget; - connect(m_pRootWidget, TQT_SIGNAL(wheelRolled(int)), this, TQT_SLOT(slotSwitchDesktops(int))); - connect(m_pRootWidget, TQT_SIGNAL(colorDropEvent(TQDropEvent*)), this, TQT_SLOT(handleColorDropEvent(TQDropEvent*)) ); - connect(m_pRootWidget, TQT_SIGNAL(imageDropEvent(TQDropEvent*)), this, TQT_SLOT(handleImageDropEvent(TQDropEvent*)) ); - connect(m_pRootWidget, TQT_SIGNAL(newWallpaper(const KURL&)), this, TQT_SLOT(slotNewWallpaper(const KURL&)) ); - - // Geert Jansen: backgroundmanager belongs here - // TODO tell KBackgroundManager if we change widget() - bgMgr = new KBackgroundManager( m_pIconView, m_pKwinmodule ); - bgMgr->setExport(1); - connect( bgMgr, TQT_SIGNAL( initDone()), TQT_SLOT( backgroundInitDone())); - if (!m_bInit) - { - delete KRootWm::self(); - KRootWm* krootwm = new KRootWm( m_pSaver, this ); // handler for root menu (used by kdesktop on RMB click) - keys->setSlot("Lock Session", krootwm, TQT_SLOT(slotLock())); - keys->updateConnections(); - } - } - else if (m_bDesktopEnabled && !m_pIconView) - { - delete bgMgr; - bgMgr = 0; - delete m_pRootWidget; - m_pRootWidget = 0; - m_pIconView = new KDIconView( this, 0 ); - connect( m_pIconView, TQT_SIGNAL( imageDropEvent( TQDropEvent * ) ), - this, TQT_SLOT( handleImageDropEvent( TQDropEvent * ) ) ); - connect( m_pIconView, TQT_SIGNAL( colorDropEvent( TQDropEvent * ) ), - this, TQT_SLOT( handleColorDropEvent( TQDropEvent * ) ) ); - connect( m_pIconView, TQT_SIGNAL( newWallpaper( const KURL & ) ), - this, TQT_SLOT( slotNewWallpaper( const KURL & ) ) ); - connect( m_pIconView, TQT_SIGNAL( wheelRolled( int ) ), - this, TQT_SLOT( slotSwitchDesktops( int ) ) ); - - // All the QScrollView/QWidget-specific stuff should go here, so that we can use - // another qscrollview/widget instead of the iconview and use the same code - m_pIconView->setVScrollBarMode( TQScrollView::AlwaysOff ); - m_pIconView->setHScrollBarMode( TQScrollView::AlwaysOff ); - m_pIconView->setDragAutoScroll( false ); - m_pIconView->setFrameStyle( TQFrame::NoFrame ); - m_pIconView->viewport()->setBackgroundMode( X11ParentRelative ); - m_pIconView->setFocusPolicy( TQ_StrongFocus ); - m_pIconView->viewport()->setFocusPolicy( TQ_StrongFocus ); - m_pIconView->setGeometry( geometry() ); - m_pIconView->show(); - - // Geert Jansen: backgroundmanager belongs here - // TODO tell KBackgroundManager if we change widget() - bgMgr = new KBackgroundManager( m_pIconView, m_pKwinmodule ); - bgMgr->setExport(1); - connect( bgMgr, TQT_SIGNAL( initDone()), TQT_SLOT( backgroundInitDone())); - - // make sure it is initialized before we first call updateWorkArea() - m_pIconView->initConfig( m_bInit ); - - // set the size of the area for desktop icons placement - { - TQByteArray data, result; - TQDataStream arg(data, IO_WriteOnly); - arg << kdesktop_screen_number; - TQCString replyType; - TQRect area; - - if ( kapp->dcopClient()->call(kicker_name, kicker_name, "desktopIconsArea(int)", - data, replyType, result, false, 2000) ) - { - TQDataStream res(result, IO_ReadOnly); - res >> area; - - m_pIconView->updateWorkArea(area); - } - else - if ( m_bInit ) - { - // if we failed to get the information from kicker wait a little - probably - // this is the KDE startup and kicker is simply not running yet - m_waitForKicker = new TQTimer(this); - connect(m_waitForKicker, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotNoKicker())); - m_waitForKicker->start(15000, true); - } - else // we are not called from the ctor, so kicker should already run - { - area = twinModule()->workArea(twinModule()->currentDesktop()); - m_pIconView->updateWorkArea(area); - } - } - - if (!m_bInit) - { - m_pIconView->start(); - delete KRootWm::self(); - KRootWm* krootwm = new KRootWm( m_pSaver, this ); // handler for root menu (used by kdesktop on RMB click) - keys->setSlot("Lock Session", krootwm, TQT_SLOT(slotLock())); - keys->updateConnections(); - } - } else { - DCOPRef r( "ksmserver", "ksmserver" ); - r.send( "resumeStartup", TQCString( "kdesktop" )); - } - - KWin::setType( winId(), NET::Desktop ); - KWin::setState( winId(), NET::SkipPager ); - KWin::setOnAllDesktops( winId(), true ); -} - -void KDesktop::slotNoKicker() -{ - kdDebug(1204) << "KDesktop::slotNoKicker ... kicker did not respond" << endl; - // up till now, we got no desktopIconsArea from kicker - probably - // it's not running, so use the area from KWinModule - TQRect area = twinModule()->workArea(twinModule()->currentDesktop()); - m_pIconView->updateWorkArea(area); -} - -void -KDesktop::backgroundInitDone() -{ - //kdDebug(1204) << "KDesktop::backgroundInitDone" << endl; - // avoid flicker - if (m_bDesktopEnabled) - { - const TQPixmap *bg = TQT_TQWIDGET(TQApplication::desktop()->screen())->backgroundPixmap(); - if ( bg ) - m_pIconView->setErasePixmap( *bg ); - - show(); - kapp->sendPostedEvents(); - } - - DCOPRef r( "ksmserver", "ksmserver" ); - r.send( "resumeStartup", TQCString( "kdesktop" )); -} - -void -KDesktop::slotStart() -{ - //kdDebug(1204) << "KDesktop::slotStart" << endl; - if (!m_bInit) return; - - // In case we started without database - KImageIO::registerFormats(); - - initConfig(); - -// if (m_bDesktopEnabled) -// { -// // We need to be visible in order to insert icons, even if the background isn't ready yet... - -// show(); -// } - - // Now we may react to configuration changes - m_bInit = false; - - if (m_pIconView) - m_pIconView->start(); - - // Global keys - keys = new TDEGlobalAccel( TQT_TQOBJECT(this) ); - (void) new KRootWm( m_pSaver, this ); - -#include "kdesktopbindings.cpp" - - keys->readSettings(); - keys->updateConnections(); - - connect(kapp, TQT_SIGNAL(appearanceChanged()), TQT_SLOT(slotConfigure())); - - TQTimer::singleShot(300, this, TQT_SLOT( slotUpAndRunning() )); -} - -void -KDesktop::runAutoStart() -{ - // 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 - TQDir dir( TDEGlobalSettings::autostartPath() ); - TQStringList entries = dir.entryList( TQDir::Files ); - TQStringList::Iterator it = entries.begin(); - TQStringList::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) != "#" ) ) - { - KURL url; - url.setPath( dir.absPath() + '/' + (*it) ); - (void) new KRun( url, 0, true ); - } - } -} - -// ----------------------------------------------------------------------------- - -KDesktop::~KDesktop() -{ - delete m_miniCli; - m_miniCli = 0; // see #120382 - delete bgMgr; - bgMgr = 0; - delete startup_id; -} - -// ----------------------------------------------------------------------------- - -void KDesktop::initConfig() -{ - if (m_pIconView) - m_pIconView->initConfig( m_bInit ); - - if ( keys ) - { - keys->readSettings(); - keys->updateConnections(); - } - - TDELaunchSettings::self()->readConfig(); - if( !TDELaunchSettings::busyCursor() ) - { - delete startup_id; - startup_id = NULL; - } - else - { - if( startup_id == NULL ) - startup_id = new StartupId; - startup_id->configure(); - } - - set_vroot = KDesktopSettings::setVRoot(); - slotSetVRoot(); // start timer - - m_bWheelSwitchesWorkspace = KDesktopSettings::wheelSwitchesWorkspace(); - - const char* forward_string = m_wheelDirectionStrings[Forward]; - m_eWheelDirection = - (KDesktopSettings::wheelDirection() == forward_string) ? Forward : Reverse; -} - -// ----------------------------------------------------------------------------- - -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(); -} - -/* - Shows minicli - */ -void KDesktop::popupExecuteCommand() -{ - popupExecuteCommand(""); -} - -void KDesktop::popupExecuteCommand(const TQString& command) -{ - if (m_bInit) - return; - - if (!kapp->authorize("run_command")) - return; - - // Created on demand - if ( !m_miniCli ) - { - m_miniCli = new Minicli( this ); - m_miniCli->adjustSize(); // for the centering below - } - - if (!command.isEmpty()) - m_miniCli->setCommand(command); - - // Move minicli to the current desktop - NETWinInfo info( tqt_xdisplay(), m_miniCli->winId(), tqt_xrootwin(), NET::WMDesktop ); - int currentDesktop = twinModule()->currentDesktop(); - if ( info.desktop() != currentDesktop ) - info.setDesktop( currentDesktop ); - - if ( m_miniCli->isVisible() ) { - KWin::forceActiveWindow( m_miniCli->winId() ); - } else { - NETRootInfo i( tqt_xdisplay(), NET::Supported ); - if( !i.isSupported( NET::WM2FullPlacement )) { - TQRect rect = TDEGlobalSettings::desktopGeometry(TQCursor::pos()); - m_miniCli->move(rect.x() + (rect.width() - m_miniCli->width())/2, - rect.y() + (rect.height() - m_miniCli->height())/2); - } - m_miniCli->show(); // non-modal - } -} - -void KDesktop::slotSwitchUser() -{ - KRootWm::self()->slotSwitchUser(); -} - -void KDesktop::slotShowWindowList() -{ - KRootWm::self()->slotWindowList(); -} - -void KDesktop::slotShowTaskManager() -{ - //kdDebug(1204) << "Launching KSysGuard..." << endl; - TDEProcess* p = new TDEProcess; - TQ_CHECK_PTR(p); - - *p << "ksysguard"; - *p << "--showprocesses"; - - p->start(TDEProcess::DontCare); - - delete p; -} - -// ----------------------------------------------------------------------------- - -void KDesktop::rearrangeIcons() -{ - if (m_pIconView) - m_pIconView->rearrangeIcons(); -} - -void KDesktop::lineupIcons() -{ - if (m_pIconView) - m_pIconView->lineupIcons(); -} - -void KDesktop::selectAll() -{ - if (m_pIconView) - m_pIconView->selectAll( true ); -} - -void KDesktop::unselectAll() -{ - if (m_pIconView) - m_pIconView->selectAll( false ); -} - -TQStringList KDesktop::selectedURLs() -{ - if (m_pIconView) - return m_pIconView->selectedURLs(); - return TQStringList(); -} - -void KDesktop::refreshIcons() -{ - if (m_pIconView) - m_pIconView->refreshIcons(); -} - -void KDesktop::setShowDesktop( bool b ) -{ - bool m_showingDesktop = showDesktopState(); - - if (b == m_showingDesktop) - { - return; - } - - if( m_wmSupport ) - { - NETRootInfo i( tqt_xdisplay(), 0 ); - i.setShowingDesktop( b ); - return; - } - - if (b) - { - m_activeWindow = twinModule()->activeWindow(); - m_iconifiedList.clear(); - - const TQValueList windows = twinModule()->windows(); - for (TQValueList::ConstIterator it = windows.begin(); - it != windows.end(); - ++it) - { - WId w = *it; - - NETWinInfo info( tqt_xdisplay(), w, tqt_xrootwin(), - NET::XAWMState | NET::WMDesktop ); - - if (info.mappingState() == NET::Visible && - (info.desktop() == NETWinInfo::OnAllDesktops || - info.desktop() == (int)twinModule()->currentDesktop())) - { - m_iconifiedList.append( w ); - } - } - - // find first, hide later, otherwise transients may get minimized - // with the window they're transient for - for (TQValueVector::Iterator it = m_iconifiedList.begin(); - it != m_iconifiedList.end(); - ++it) - { - KWin::iconifyWindow( *it, false ); - } - - // on desktop changes or when a window is deiconified, we abort the show desktop mode - connect(twinModule(), TQT_SIGNAL(currentDesktopChanged(int)), - TQT_SLOT(slotCurrentDesktopChanged(int))); - connect(twinModule(), TQT_SIGNAL(windowChanged(WId,unsigned int)), - TQT_SLOT(slotWindowChanged(WId,unsigned int))); - connect(twinModule(), TQT_SIGNAL(windowAdded(WId)), - TQT_SLOT(slotWindowAdded(WId))); - } - else - { - disconnect(twinModule(), TQT_SIGNAL(currentDesktopChanged(int)), - this, TQT_SLOT(slotCurrentDesktopChanged(int))); - disconnect(twinModule(), TQT_SIGNAL(windowChanged(WId,unsigned int)), - this, TQT_SLOT(slotWindowChanged(WId,unsigned int))); - disconnect(twinModule(), TQT_SIGNAL(windowAdded(WId)), - this, TQT_SLOT(slotWindowAdded(WId))); - - for (TQValueVector::ConstIterator it = m_iconifiedList.begin(); - it != m_iconifiedList.end(); - ++it) - { - KWin::deIconifyWindow(*it, false); - } - - KWin::forceActiveWindow(m_activeWindow); - } - - m_showingDesktop = b; - emit desktopShown(m_showingDesktop); -} - -void KDesktop::slotCurrentDesktopChanged(int) -{ - setShowDesktop( false ); -} - -void KDesktop::slotWindowAdded(WId w) -{ - bool m_showingDesktop = showDesktopState(); - - if (!m_showingDesktop) - { - return; - } - - NETWinInfo inf(tqt_xdisplay(), w, tqt_xrootwin(), - NET::XAWMState | NET::WMWindowType); - NET::WindowType windowType = inf.windowType(NET::AllTypesMask); - - if ((windowType == NET::Normal || windowType == NET::Unknown) && - inf.mappingState() == NET::Visible) - { - TDEConfig twincfg( "twinrc", true ); // see in twin - twincfg.setGroup( "Windows" ); - if( twincfg.readBoolEntry( "ShowDesktopIsMinimizeAll", false )) - { - m_iconifiedList.clear(); - m_showingDesktop = false; - emit desktopShown(false); - } - else - { - m_activeWindow = w; - setShowDesktop(false); - } - } -} - -void KDesktop::slotWindowChanged(WId w, unsigned int dirty) -{ - bool m_showingDesktop = showDesktopState(); - - if (!m_showingDesktop) - { - return; - } - - if (dirty & NET::XAWMState) - { - NETWinInfo inf(tqt_xdisplay(), w, tqt_xrootwin(), - NET::XAWMState | NET::WMWindowType); - NET::WindowType windowType = inf.windowType(NET::AllTypesMask); - - if ((windowType == NET::Normal || windowType == NET::Unknown) && - inf.mappingState() == NET::Visible) - { - // a window was deiconified, abort the show desktop mode. - m_iconifiedList.clear(); - m_showingDesktop = false; - emit desktopShown(false); - } - } -} - -bool KDesktop::showDesktopState() -{ - return twinModule()->showingDesktop(); -} - -void KDesktop::toggleShowDesktop() -{ - setShowDesktop(!showDesktopState()); -} - -TDEActionCollection * KDesktop::actionCollection() -{ - if (!m_pIconView) - return 0; - return m_pIconView->actionCollection(); -} - -KURL KDesktop::url() const -{ - if (m_pIconView) - return m_pIconView->url(); - return KURL(); -} - -// ----------------------------------------------------------------------------- - -void KDesktop::slotConfigure() -{ - configure(); -} - -void KDesktop::configure() -{ - // re-read configuration and apply it - TDEGlobal::config()->reparseConfiguration(); - KDesktopSettings::self()->readConfig(); - - // If we have done start() already, then re-configure. - // Otherwise, start() will call initConfig anyway - if (!m_bInit) - { - initRoot(); - initConfig(); - KRootWm::self()->initConfig(); - } - - if (keys) - { - keys->readSettings(); - keys->updateConnections(); - } -} - -void KDesktop::slotSettingsChanged(int category) -{ - //kdDebug(1204) << "KDesktop::slotSettingsChanged" << endl; - if (category == TDEApplication::SETTINGS_PATHS) - { - kdDebug(1204) << "KDesktop::slotSettingsChanged SETTINGS_PATHS" << endl; - if (m_pIconView) - m_pIconView->recheckDesktopURL(); - } - else if (category == TDEApplication::SETTINGS_SHORTCUTS) - { - kdDebug(1204) << "KDesktop::slotSettingsChanged SETTINGS_SHORTCUTS" << endl; - keys->readSettings(); - keys->updateConnections(); - } -} - -void KDesktop::slotIconChanged(int group) -{ - if ( group == TDEIcon::Desktop ) - { - kdDebug(1204) << "KDesktop::slotIconChanged" << endl; - refresh(); - } -} - -void KDesktop::slotDatabaseChanged() -{ - //kdDebug(1204) << "KDesktop::slotDatabaseChanged" << endl; - if (m_bInit) // kded is done, now we can "start" for real - slotStart(); - if (m_pIconView && KSycoca::isChanged("mimetypes")) - m_pIconView->refreshMimeTypes(); -} - -void KDesktop::refresh() -{ - // George Staikos 3/14/01 - // This bit will just refresh the desktop and icons. Now I have code - // in KWin to do a complete refresh so this isn't really needed. - // I'll leave it in here incase the plan is changed again -#if 0 - m_bNeedRepaint |= 1; - updateWorkArea(); -#endif - kapp->dcopClient()->send( twin_name, "", "refresh()", TQString("")); - refreshIcons(); -} - -// ----------------------------------------------------------------------------- - -void KDesktop::slotSetVRoot() -{ - if (!m_pIconView) - return; - - if (KWin::windowInfo(winId()).mappingState() == NET::Withdrawn) { - TQTimer::singleShot(100, this, TQT_SLOT(slotSetVRoot())); - return; - } - - unsigned long rw = RootWindowOfScreen(ScreenOfDisplay(tqt_xdisplay(), tqt_xscreen())); - unsigned long vroot_data[1] = { m_pIconView->viewport()->winId() }; - static Atom vroot = XInternAtom(tqt_xdisplay(), "__SWM_VROOT", False); - - Window rootReturn, parentReturn, *children; - unsigned int numChildren; - Window top = winId(); - while (1) { - /*int ret = */XQueryTree(tqt_xdisplay(), top , &rootReturn, &parentReturn, - &children, &numChildren); - if (children) - XFree((char *)children); - if (parentReturn == rw) { - break; - } else - top = parentReturn; - } - if ( set_vroot ) - XChangeProperty(tqt_xdisplay(), top, vroot, XA_WINDOW, 32, - PropModeReplace, (unsigned char *)vroot_data, 1); - else - XDeleteProperty (tqt_xdisplay(), top, vroot); -} - -// ----------------------------------------------------------------------------- - -void KDesktop::slotShutdown() -{ - if ( m_pIconView ) - m_pIconView->saveIconPositions(); - if ( m_miniCli ) - m_miniCli->saveConfig(); -} - -// don't hide when someone presses Alt-F4 on us -void KDesktop::closeEvent(TQCloseEvent *e) -{ - e->ignore(); -} - -void KDesktop::desktopIconsAreaChanged(const TQRect &area, int screen) -{ - // hurra! kicker is alive - if ( m_waitForKicker ) m_waitForKicker->stop(); - - // -2: all screens - // -1: primary screen - // else: screen number - - if (screen <= -2) - screen = kdesktop_screen_number; - else if (screen == -1) - screen = kapp->desktop()->primaryScreen(); - - // This is pretty broken, mixes Xinerama and non-Xinerama multihead - // and generally doesn't seem to be required anyway => ignore screen. - if ( /*(screen == kdesktop_screen_number) &&*/ m_pIconView ) { - m_pIconView->updateWorkArea(area); - } -} - -void KDesktop::slotSwitchDesktops(int delta) -{ - if(m_bWheelSwitchesWorkspace && KWin::numberOfDesktops() > 1) - { - int newDesk, curDesk = KWin::currentDesktop(); - - if( (delta < 0 && m_eWheelDirection == Forward) || (delta > 0 && m_eWheelDirection == Reverse) ) - newDesk = curDesk % KWin::numberOfDesktops() + 1; - else - newDesk = ( KWin::numberOfDesktops() + curDesk - 2 ) % KWin::numberOfDesktops() + 1; - - KWin::setCurrentDesktop( newDesk ); - } -} - -void KDesktop::handleColorDropEvent(TQDropEvent * e) -{ - TDEPopupMenu popup; - popup.insertItem(SmallIconSet("colors"),i18n("Set as Primary Background Color"), 1); - popup.insertItem(SmallIconSet("colors"),i18n("Set as Secondary Background Color"), 2); - int result = popup.exec(e->pos()); - - TQColor c; - KColorDrag::decode(e, c); - switch (result) { - case 1: bgMgr->setColor(c, true); break; - case 2: bgMgr->setColor(c, false); break; - default: return; - } - bgMgr->setWallpaper(0,0); -} - -void KDesktop::handleImageDropEvent(TQDropEvent * e) -{ - TDEPopupMenu popup; - if ( m_pIconView ) - popup.insertItem(SmallIconSet("document-save"),i18n("&Save to Desktop..."), 1); - if ( ( m_pIconView && m_pIconView->maySetWallpaper() ) || m_pRootWidget ) - popup.insertItem(SmallIconSet("background"),i18n("Set as &Wallpaper"), 2); - popup.insertSeparator(); - popup.insertItem(SmallIconSet("cancel"), i18n("&Cancel")); - int result = popup.exec(e->pos()); - - if (result == 1) - { - bool ok = true; - TQString filename = KInputDialog::getText(TQString::null, i18n("Enter a name for the image below:"), TQString::null, &ok, m_pIconView); - - if (!ok) - { - return; - } - - if (filename.isEmpty()) - { - filename = i18n("image.png"); - } - else if (filename.right(4).lower() != ".png") - { - filename += ".png"; - } - - TQImage i; - TQImageDrag::decode(e, i); - KTempFile tmpFile(TQString::null, filename); - i.save(tmpFile.name(), "PNG"); - // We pass 0 as parent window because passing the desktop is not a good idea - KURL src; - src.setPath( tmpFile.name() ); - KURL dest( KDIconView::desktopURL() ); - dest.addPath( filename ); - TDEIO::NetAccess::copy( src, dest, 0 ); - tmpFile.unlink(); - } - else if (result == 2) - { - TQImage i; - TQImageDrag::decode(e, i); - KTempFile tmpFile(TDEGlobal::dirs()->saveLocation("wallpaper"), ".png"); - i.save(tmpFile.name(), "PNG"); - kdDebug(1204) << "KDesktop::contentsDropEvent " << tmpFile.name() << endl; - bgMgr->setWallpaper(tmpFile.name()); - } -} - -void KDesktop::slotNewWallpaper(const KURL &url) -{ - // This is called when a file containing an image is dropped - // (called by KonqOperations) - if ( url.isLocalFile() ) - bgMgr->setWallpaper( url.path() ); - else - { - // Figure out extension - TQString fileName = url.fileName(); - TQFileInfo fileInfo( fileName ); - TQString ext = fileInfo.extension(); - // Store tempfile in a place where it will still be available after a reboot - KTempFile tmpFile( TDEGlobal::dirs()->saveLocation("wallpaper"), "." + ext ); - KURL localURL; localURL.setPath( tmpFile.name() ); - // We pass 0 as parent window because passing the desktop is not a good idea - TDEIO::NetAccess::file_copy( url, localURL, -1, true /*overwrite*/ ); - bgMgr->setWallpaper( localURL.path() ); - } -} - -// for dcop interface backward compatibility -void KDesktop::logout() -{ - logout( TDEApplication::ShutdownConfirmDefault, - TDEApplication::ShutdownTypeNone ); -} - -void KDesktop::logout( TDEApplication::ShutdownConfirm confirm, - TDEApplication::ShutdownType sdtype ) -{ - if( !kapp->requestShutDown( confirm, sdtype ) ) - // this i18n string is also in kicker/applets/run/runapplet - KMessageBox::error( this, i18n("Could not log out properly.\nThe session manager cannot " - "be contacted. You can try to force a shutdown by pressing " - "Ctrl+Alt+Backspace; note, however, that your current session " - "will not be saved with a forced shutdown." ) ); -} - -void KDesktop::slotLogout() -{ - logout( TDEApplication::ShutdownConfirmDefault, - TDEApplication::ShutdownTypeDefault ); -} - -void KDesktop::slotLogoutNoCnf() -{ - logout( TDEApplication::ShutdownConfirmNo, - TDEApplication::ShutdownTypeNone ); -} - -void KDesktop::slotHaltNoCnf() -{ - logout( TDEApplication::ShutdownConfirmNo, - TDEApplication::ShutdownTypeHalt ); -} - -void KDesktop::slotRebootNoCnf() -{ - logout( TDEApplication::ShutdownConfirmNo, - TDEApplication::ShutdownTypeReboot ); -} - -void KDesktop::setVRoot( bool enable ) -{ - if ( enable == set_vroot ) - return; - - set_vroot = enable; - kdDebug(1204) << "setVRoot " << enable << endl; - KDesktopSettings::setSetVRoot( set_vroot ); - KDesktopSettings::writeConfig(); - slotSetVRoot(); -} - -void KDesktop::clearCommandHistory() -{ - if ( m_miniCli ) - m_miniCli->clearHistory(); -} - -void KDesktop::setIconsEnabled( bool enable ) -{ - if ( enable == m_bDesktopEnabled ) - return; - - m_bDesktopEnabled = enable; - kdDebug(1204) << "setIcons " << enable << endl; - KDesktopSettings::setDesktopEnabled( m_bDesktopEnabled ); - KDesktopSettings::writeConfig(); - if (!enable) { - delete m_pIconView; - m_pIconView = 0; - } - configure(); -} - -void KDesktop::desktopResized() -{ - resize(kapp->desktop()->size()); - - if ( m_pIconView ) - { - // the sequence of actions is important: - // remove all icons, resize desktop, tell kdiconview new iconsArea size - // tell kdiconview to reget all icons - m_pIconView->slotClear(); - m_pIconView->resize(kapp->desktop()->size()); - - // get new desktopIconsArea from kicker - TQByteArray data, result; - TQDataStream arg(data, IO_WriteOnly); - arg << kdesktop_screen_number; - TQCString replyType; - TQRect area; - - if ( kapp->dcopClient()->call(kicker_name, kicker_name, "desktopIconsArea(int)", - data, replyType, result, false, 2000) ) - { - TQDataStream res(result, IO_ReadOnly); - res >> area; - } - else - { - area = twinModule()->workArea(twinModule()->currentDesktop()); - } - - m_pIconView->updateWorkArea(area); - m_pIconView->startDirLister(); - } -} - -void KDesktop::switchDesktops( int delta ) -{ - bool old = m_bWheelSwitchesWorkspace; - m_bWheelSwitchesWorkspace = true; - slotSwitchDesktops(delta); - m_bWheelSwitchesWorkspace = old; -} - -bool KDesktop::event(TQEvent * e) -{ - if ( e->type() == TQEvent::WindowDeactivate) - { - if (m_pIconView) - m_pIconView->clearSelection(); - } - return TQWidget::event(e); -} - -TQPoint KDesktop::findPlaceForIcon( int column, int row ) -{ - if (m_pIconView) - return m_pIconView->findPlaceForIcon(column, row); - else - return TQPoint(-1, -1); -} - -void KDesktop::addIcon(const TQString & _url, int x, int y) -{ - addIcon( _url, TDEGlobalSettings::desktopPath(), x, y ); -} - -void KDesktop::addIcon(const TQString & _url, const TQString & _dest, int x, int y) -{ - TQString filename = _url.mid(_url.findRev('/') + 1); - - TQValueList files; - TDEIO::CopyInfo i; - i.uSource = KURL::fromPathOrURL( _url ); - i.uDest = KURL::fromPathOrURL( _dest ); - i.uDest.addPath( filename ); - files.append(i); - if (!TQFile::exists(i.uDest.prettyURL().replace("file://",TQString()))) { m_pIconView->slotAboutToCreate( TQPoint( x, y ), files ); - TDEIO::copy( i.uSource, i.uDest, false ); } - -// m_pIconView->addFuturePosition(filename, x, y); - // tqDebug("addIcon %s %s %d %d", _url.latin1(), _dest.latin1(), x, y); -// system(TQString("cp \"%1\" \"%2/%3\"").arg(KURL(_url).path()).arg(KURL(_dest).path()).arg(filename).latin1()); -// m_pIconView->update( _dest ); -} - -void KDesktop::removeIcon(const TQString &_url) -{ - if (_url.at(0) != '/') { - tqDebug("removeIcon with relative path not supported for now"); - return; - } - unlink(KURL(_url).path().latin1()); - TQString dest = _url.left(_url.findRev('/') + 1); - m_pIconView->update( dest ); -} - -#include "desktop.moc" diff --git a/kdesktop/desktop.cpp b/kdesktop/desktop.cpp new file mode 100644 index 000000000..2732bff08 --- /dev/null +++ b/kdesktop/desktop.cpp @@ -0,0 +1,1197 @@ +/* This file is part of the KDE project + Copyright (C) 1998, 1999 Torben Weis + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + + +#include "desktop.h" +#include "krootwm.h" +#include "bgmanager.h" +#include "bgsettings.h" +#include "startupid.h" +#include "kdiconview.h" +#include "minicli.h" +#include "kdesktopsettings.h" +#include "tdelaunchsettings.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 +#include +// Create the equivalent of TDEAccelBase::connectItem +// and then remove this include and fix reconnects in initRoot() -- ellis +//#include + +extern int kdesktop_screen_number; +extern TQCString kdesktop_name, kicker_name, twin_name; + +KRootWidget::KRootWidget() : TQObject() +{ + kapp->desktop()->installEventFilter(this); + kapp->desktop()->setAcceptDrops( true ); +} + +bool KRootWidget::eventFilter ( TQObject *, TQEvent * e ) +{ + if (e->type() == TQEvent::MouseButtonPress) + { + TQMouseEvent *me = TQT_TQMOUSEEVENT(e); + KRootWm::self()->mousePressed( me->globalPos(), me->button() ); + return true; + } + else if (e->type() == TQEvent::Wheel) + { + TQWheelEvent *we = TQT_TQWHEELEVENT(e); + emit wheelRolled(we->delta()); + return true; + } + else if ( e->type() == TQEvent::DragEnter ) + { + TQDragEnterEvent* de = static_cast( e ); + bool b = !TDEGlobal::config()->isImmutable() && !TDEGlobal::dirs()->isRestrictedResource( "wallpaper" ); + + bool imageURL = false; + if ( KURLDrag::canDecode( de ) ) + { + KURL::List list; + KURLDrag::decode( de, list ); + KURL url = list.first(); + KMimeType::Ptr mime = KMimeType::findByURL( url ); + if ( !KImageIO::type( url.path() ).isEmpty() || + KImageIO::isSupported( mime->name(), KImageIO::Reading ) || mime->is( "image/svg+xml" ) ) + imageURL = true; + } + + b = b && ( KColorDrag::canDecode( de ) || TQImageDrag::canDecode( de ) || imageURL ); + de->accept( b ); + return true; + } + else if ( e->type() == TQEvent::Drop ) + { + TQDropEvent* de = static_cast( e ); + if ( KColorDrag::canDecode( de ) ) + emit colorDropEvent( de ); + else if ( TQImageDrag::canDecode( de ) ) + emit imageDropEvent( de ); + else if ( KURLDrag::canDecode( de ) ) { + KURL::List list; + KURLDrag::decode( de, list ); + KURL url = list.first(); + emit newWallpaper( url ); + } + return true; + } + return false; // Don't filter. +} + +// ----------------------------------------------------------------------------- +#define DEFAULT_DELETEACTION 1 + +KDesktop::WheelDirection KDesktop::m_eWheelDirection = KDesktop::m_eDefaultWheelDirection; +const char* KDesktop::m_wheelDirectionStrings[2] = { "Forward", "Reverse" }; + +KDesktop::KDesktop( SaverEngine* saver, bool x_root_hack, bool wait_for_kded ) : + TQWidget( 0L, "desktop", (WFlags)(WResizeNoErase | ( x_root_hack ? (WStyle_Customize | WStyle_NoBorder) : 0)) ), + KDesktopIface(), + // those two WStyle_ break kdesktop when the root-hack isn't used (no Dnd) + startup_id( NULL ), m_waitForKicker(0) +{ + m_pSaver = saver; + + NETRootInfo i( tqt_xdisplay(), NET::Supported ); + m_wmSupport = i.isSupported( NET::WM2ShowingDesktop ); + + m_bWaitForKded = wait_for_kded; + m_miniCli = 0; // created on demand + keys = 0; // created later + TDEGlobal::locale()->insertCatalogue("kdesktop"); + TDEGlobal::locale()->insertCatalogue("libkonq"); // needed for apps using libkonq + TDEGlobal::locale()->insertCatalogue("libdmctl"); + + setCaption( "KDE Desktop"); + + setAcceptDrops(true); // WStyle_Customize seems to disable that + m_pKwinmodule = new KWinModule( TQT_TQOBJECT(this) ); + + kapp->dcopClient()->setNotifications(true); + kapp->dcopClient()->connectDCOPSignal(kicker_name, kicker_name, "desktopIconsAreaChanged(TQRect, int)", + "KDesktopIface", "desktopIconsAreaChanged(TQRect, int)", false); + + // Dont repaint on configuration changes during construction + m_bInit = true; + + // It's the child widget that gets the focus, not us + setFocusPolicy( TQ_NoFocus ); + + if ( x_root_hack ) + { + // this is a ugly hack to make Dnd work + // Matthias told me that it won't be necessary with twin + // actually my first try with ICCCM (Dirk) :-) + unsigned long data[2]; + data[0] = (unsigned long) 1; + data[1] = (unsigned long) 0; // None; (Werner) + Atom wm_state = XInternAtom(tqt_xdisplay(), "WM_STATE", False); + XChangeProperty(tqt_xdisplay(), winId(), wm_state, wm_state, 32, + PropModeReplace, (unsigned char *)data, 2); + + } + + setGeometry( TQApplication::desktop()->geometry() ); + lower(); + + connect( kapp, TQT_SIGNAL( shutDown() ), + this, TQT_SLOT( slotShutdown() ) ); + + connect(kapp, TQT_SIGNAL(settingsChanged(int)), + this, TQT_SLOT(slotSettingsChanged(int))); + kapp->addKipcEventMask(KIPC::SettingsChanged); + + kapp->addKipcEventMask(KIPC::IconChanged); + connect(kapp, TQT_SIGNAL(iconChanged(int)), this, TQT_SLOT(slotIconChanged(int))); + + connect(KSycoca::self(), TQT_SIGNAL(databaseChanged()), + this, TQT_SLOT(slotDatabaseChanged())); + + m_pIconView = 0; + m_pRootWidget = 0; + bgMgr = 0; + initRoot(); + + TQTimer::singleShot(0, this, TQT_SLOT( slotStart() )); + +#if (TQT_VERSION-0 >= 0x030200) // XRANDR support + connect( kapp->desktop(), TQT_SIGNAL( resized( int )), TQT_SLOT( desktopResized())); +#endif +} + +void +KDesktop::initRoot() +{ + Display *dpy = tqt_xdisplay(); + Window root = RootWindow(dpy, kdesktop_screen_number); + XDefineCursor(dpy, root, cursor().handle()); + + m_bDesktopEnabled = KDesktopSettings::desktopEnabled(); + if ( !m_bDesktopEnabled && !m_pRootWidget ) + { + hide(); + delete bgMgr; + bgMgr = 0; + if ( m_pIconView ) + m_pIconView->saveIconPositions(); + delete m_pIconView; + m_pIconView = 0; + + { // trigger creation of QToolTipManager, it does XSelectInput() on the root window + TQWidget w; + TQToolTip::add( &w, "foo" ); + } + // NOTE: If mouse clicks stop working again, it's most probably something doing XSelectInput() + // on the root window after this, and setting it to some fixed value instead of adding its mask. + XWindowAttributes attrs; + XGetWindowAttributes(dpy, root, &attrs); + XSelectInput(dpy, root, attrs.your_event_mask | ButtonPressMask); + + m_pRootWidget = new KRootWidget; + connect(m_pRootWidget, TQT_SIGNAL(wheelRolled(int)), this, TQT_SLOT(slotSwitchDesktops(int))); + connect(m_pRootWidget, TQT_SIGNAL(colorDropEvent(TQDropEvent*)), this, TQT_SLOT(handleColorDropEvent(TQDropEvent*)) ); + connect(m_pRootWidget, TQT_SIGNAL(imageDropEvent(TQDropEvent*)), this, TQT_SLOT(handleImageDropEvent(TQDropEvent*)) ); + connect(m_pRootWidget, TQT_SIGNAL(newWallpaper(const KURL&)), this, TQT_SLOT(slotNewWallpaper(const KURL&)) ); + + // Geert Jansen: backgroundmanager belongs here + // TODO tell KBackgroundManager if we change widget() + bgMgr = new KBackgroundManager( m_pIconView, m_pKwinmodule ); + bgMgr->setExport(1); + connect( bgMgr, TQT_SIGNAL( initDone()), TQT_SLOT( backgroundInitDone())); + if (!m_bInit) + { + delete KRootWm::self(); + KRootWm* krootwm = new KRootWm( m_pSaver, this ); // handler for root menu (used by kdesktop on RMB click) + keys->setSlot("Lock Session", krootwm, TQT_SLOT(slotLock())); + keys->updateConnections(); + } + } + else if (m_bDesktopEnabled && !m_pIconView) + { + delete bgMgr; + bgMgr = 0; + delete m_pRootWidget; + m_pRootWidget = 0; + m_pIconView = new KDIconView( this, 0 ); + connect( m_pIconView, TQT_SIGNAL( imageDropEvent( TQDropEvent * ) ), + this, TQT_SLOT( handleImageDropEvent( TQDropEvent * ) ) ); + connect( m_pIconView, TQT_SIGNAL( colorDropEvent( TQDropEvent * ) ), + this, TQT_SLOT( handleColorDropEvent( TQDropEvent * ) ) ); + connect( m_pIconView, TQT_SIGNAL( newWallpaper( const KURL & ) ), + this, TQT_SLOT( slotNewWallpaper( const KURL & ) ) ); + connect( m_pIconView, TQT_SIGNAL( wheelRolled( int ) ), + this, TQT_SLOT( slotSwitchDesktops( int ) ) ); + + // All the QScrollView/QWidget-specific stuff should go here, so that we can use + // another qscrollview/widget instead of the iconview and use the same code + m_pIconView->setVScrollBarMode( TQScrollView::AlwaysOff ); + m_pIconView->setHScrollBarMode( TQScrollView::AlwaysOff ); + m_pIconView->setDragAutoScroll( false ); + m_pIconView->setFrameStyle( TQFrame::NoFrame ); + m_pIconView->viewport()->setBackgroundMode( X11ParentRelative ); + m_pIconView->setFocusPolicy( TQ_StrongFocus ); + m_pIconView->viewport()->setFocusPolicy( TQ_StrongFocus ); + m_pIconView->setGeometry( geometry() ); + m_pIconView->show(); + + // Geert Jansen: backgroundmanager belongs here + // TODO tell KBackgroundManager if we change widget() + bgMgr = new KBackgroundManager( m_pIconView, m_pKwinmodule ); + bgMgr->setExport(1); + connect( bgMgr, TQT_SIGNAL( initDone()), TQT_SLOT( backgroundInitDone())); + + // make sure it is initialized before we first call updateWorkArea() + m_pIconView->initConfig( m_bInit ); + + // set the size of the area for desktop icons placement + { + TQByteArray data, result; + TQDataStream arg(data, IO_WriteOnly); + arg << kdesktop_screen_number; + TQCString replyType; + TQRect area; + + if ( kapp->dcopClient()->call(kicker_name, kicker_name, "desktopIconsArea(int)", + data, replyType, result, false, 2000) ) + { + TQDataStream res(result, IO_ReadOnly); + res >> area; + + m_pIconView->updateWorkArea(area); + } + else + if ( m_bInit ) + { + // if we failed to get the information from kicker wait a little - probably + // this is the KDE startup and kicker is simply not running yet + m_waitForKicker = new TQTimer(this); + connect(m_waitForKicker, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotNoKicker())); + m_waitForKicker->start(15000, true); + } + else // we are not called from the ctor, so kicker should already run + { + area = twinModule()->workArea(twinModule()->currentDesktop()); + m_pIconView->updateWorkArea(area); + } + } + + if (!m_bInit) + { + m_pIconView->start(); + delete KRootWm::self(); + KRootWm* krootwm = new KRootWm( m_pSaver, this ); // handler for root menu (used by kdesktop on RMB click) + keys->setSlot("Lock Session", krootwm, TQT_SLOT(slotLock())); + keys->updateConnections(); + } + } else { + DCOPRef r( "ksmserver", "ksmserver" ); + r.send( "resumeStartup", TQCString( "kdesktop" )); + } + + KWin::setType( winId(), NET::Desktop ); + KWin::setState( winId(), NET::SkipPager ); + KWin::setOnAllDesktops( winId(), true ); +} + +void KDesktop::slotNoKicker() +{ + kdDebug(1204) << "KDesktop::slotNoKicker ... kicker did not respond" << endl; + // up till now, we got no desktopIconsArea from kicker - probably + // it's not running, so use the area from KWinModule + TQRect area = twinModule()->workArea(twinModule()->currentDesktop()); + m_pIconView->updateWorkArea(area); +} + +void +KDesktop::backgroundInitDone() +{ + //kdDebug(1204) << "KDesktop::backgroundInitDone" << endl; + // avoid flicker + if (m_bDesktopEnabled) + { + const TQPixmap *bg = TQT_TQWIDGET(TQApplication::desktop()->screen())->backgroundPixmap(); + if ( bg ) + m_pIconView->setErasePixmap( *bg ); + + show(); + kapp->sendPostedEvents(); + } + + DCOPRef r( "ksmserver", "ksmserver" ); + r.send( "resumeStartup", TQCString( "kdesktop" )); +} + +void +KDesktop::slotStart() +{ + //kdDebug(1204) << "KDesktop::slotStart" << endl; + if (!m_bInit) return; + + // In case we started without database + KImageIO::registerFormats(); + + initConfig(); + +// if (m_bDesktopEnabled) +// { +// // We need to be visible in order to insert icons, even if the background isn't ready yet... + +// show(); +// } + + // Now we may react to configuration changes + m_bInit = false; + + if (m_pIconView) + m_pIconView->start(); + + // Global keys + keys = new TDEGlobalAccel( TQT_TQOBJECT(this) ); + (void) new KRootWm( m_pSaver, this ); + +#include "kdesktopbindings.cpp" + + keys->readSettings(); + keys->updateConnections(); + + connect(kapp, TQT_SIGNAL(appearanceChanged()), TQT_SLOT(slotConfigure())); + + TQTimer::singleShot(300, this, TQT_SLOT( slotUpAndRunning() )); +} + +void +KDesktop::runAutoStart() +{ + // 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 + TQDir dir( TDEGlobalSettings::autostartPath() ); + TQStringList entries = dir.entryList( TQDir::Files ); + TQStringList::Iterator it = entries.begin(); + TQStringList::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) != "#" ) ) + { + KURL url; + url.setPath( dir.absPath() + '/' + (*it) ); + (void) new KRun( url, 0, true ); + } + } +} + +// ----------------------------------------------------------------------------- + +KDesktop::~KDesktop() +{ + delete m_miniCli; + m_miniCli = 0; // see #120382 + delete bgMgr; + bgMgr = 0; + delete startup_id; +} + +// ----------------------------------------------------------------------------- + +void KDesktop::initConfig() +{ + if (m_pIconView) + m_pIconView->initConfig( m_bInit ); + + if ( keys ) + { + keys->readSettings(); + keys->updateConnections(); + } + + TDELaunchSettings::self()->readConfig(); + if( !TDELaunchSettings::busyCursor() ) + { + delete startup_id; + startup_id = NULL; + } + else + { + if( startup_id == NULL ) + startup_id = new StartupId; + startup_id->configure(); + } + + set_vroot = KDesktopSettings::setVRoot(); + slotSetVRoot(); // start timer + + m_bWheelSwitchesWorkspace = KDesktopSettings::wheelSwitchesWorkspace(); + + const char* forward_string = m_wheelDirectionStrings[Forward]; + m_eWheelDirection = + (KDesktopSettings::wheelDirection() == forward_string) ? Forward : Reverse; +} + +// ----------------------------------------------------------------------------- + +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(); +} + +/* + Shows minicli + */ +void KDesktop::popupExecuteCommand() +{ + popupExecuteCommand(""); +} + +void KDesktop::popupExecuteCommand(const TQString& command) +{ + if (m_bInit) + return; + + if (!kapp->authorize("run_command")) + return; + + // Created on demand + if ( !m_miniCli ) + { + m_miniCli = new Minicli( this ); + m_miniCli->adjustSize(); // for the centering below + } + + if (!command.isEmpty()) + m_miniCli->setCommand(command); + + // Move minicli to the current desktop + NETWinInfo info( tqt_xdisplay(), m_miniCli->winId(), tqt_xrootwin(), NET::WMDesktop ); + int currentDesktop = twinModule()->currentDesktop(); + if ( info.desktop() != currentDesktop ) + info.setDesktop( currentDesktop ); + + if ( m_miniCli->isVisible() ) { + KWin::forceActiveWindow( m_miniCli->winId() ); + } else { + NETRootInfo i( tqt_xdisplay(), NET::Supported ); + if( !i.isSupported( NET::WM2FullPlacement )) { + TQRect rect = TDEGlobalSettings::desktopGeometry(TQCursor::pos()); + m_miniCli->move(rect.x() + (rect.width() - m_miniCli->width())/2, + rect.y() + (rect.height() - m_miniCli->height())/2); + } + m_miniCli->show(); // non-modal + } +} + +void KDesktop::slotSwitchUser() +{ + KRootWm::self()->slotSwitchUser(); +} + +void KDesktop::slotShowWindowList() +{ + KRootWm::self()->slotWindowList(); +} + +void KDesktop::slotShowTaskManager() +{ + //kdDebug(1204) << "Launching KSysGuard..." << endl; + TDEProcess* p = new TDEProcess; + TQ_CHECK_PTR(p); + + *p << "ksysguard"; + *p << "--showprocesses"; + + p->start(TDEProcess::DontCare); + + delete p; +} + +// ----------------------------------------------------------------------------- + +void KDesktop::rearrangeIcons() +{ + if (m_pIconView) + m_pIconView->rearrangeIcons(); +} + +void KDesktop::lineupIcons() +{ + if (m_pIconView) + m_pIconView->lineupIcons(); +} + +void KDesktop::selectAll() +{ + if (m_pIconView) + m_pIconView->selectAll( true ); +} + +void KDesktop::unselectAll() +{ + if (m_pIconView) + m_pIconView->selectAll( false ); +} + +TQStringList KDesktop::selectedURLs() +{ + if (m_pIconView) + return m_pIconView->selectedURLs(); + return TQStringList(); +} + +void KDesktop::refreshIcons() +{ + if (m_pIconView) + m_pIconView->refreshIcons(); +} + +void KDesktop::setShowDesktop( bool b ) +{ + bool m_showingDesktop = showDesktopState(); + + if (b == m_showingDesktop) + { + return; + } + + if( m_wmSupport ) + { + NETRootInfo i( tqt_xdisplay(), 0 ); + i.setShowingDesktop( b ); + return; + } + + if (b) + { + m_activeWindow = twinModule()->activeWindow(); + m_iconifiedList.clear(); + + const TQValueList windows = twinModule()->windows(); + for (TQValueList::ConstIterator it = windows.begin(); + it != windows.end(); + ++it) + { + WId w = *it; + + NETWinInfo info( tqt_xdisplay(), w, tqt_xrootwin(), + NET::XAWMState | NET::WMDesktop ); + + if (info.mappingState() == NET::Visible && + (info.desktop() == NETWinInfo::OnAllDesktops || + info.desktop() == (int)twinModule()->currentDesktop())) + { + m_iconifiedList.append( w ); + } + } + + // find first, hide later, otherwise transients may get minimized + // with the window they're transient for + for (TQValueVector::Iterator it = m_iconifiedList.begin(); + it != m_iconifiedList.end(); + ++it) + { + KWin::iconifyWindow( *it, false ); + } + + // on desktop changes or when a window is deiconified, we abort the show desktop mode + connect(twinModule(), TQT_SIGNAL(currentDesktopChanged(int)), + TQT_SLOT(slotCurrentDesktopChanged(int))); + connect(twinModule(), TQT_SIGNAL(windowChanged(WId,unsigned int)), + TQT_SLOT(slotWindowChanged(WId,unsigned int))); + connect(twinModule(), TQT_SIGNAL(windowAdded(WId)), + TQT_SLOT(slotWindowAdded(WId))); + } + else + { + disconnect(twinModule(), TQT_SIGNAL(currentDesktopChanged(int)), + this, TQT_SLOT(slotCurrentDesktopChanged(int))); + disconnect(twinModule(), TQT_SIGNAL(windowChanged(WId,unsigned int)), + this, TQT_SLOT(slotWindowChanged(WId,unsigned int))); + disconnect(twinModule(), TQT_SIGNAL(windowAdded(WId)), + this, TQT_SLOT(slotWindowAdded(WId))); + + for (TQValueVector::ConstIterator it = m_iconifiedList.begin(); + it != m_iconifiedList.end(); + ++it) + { + KWin::deIconifyWindow(*it, false); + } + + KWin::forceActiveWindow(m_activeWindow); + } + + m_showingDesktop = b; + emit desktopShown(m_showingDesktop); +} + +void KDesktop::slotCurrentDesktopChanged(int) +{ + setShowDesktop( false ); +} + +void KDesktop::slotWindowAdded(WId w) +{ + bool m_showingDesktop = showDesktopState(); + + if (!m_showingDesktop) + { + return; + } + + NETWinInfo inf(tqt_xdisplay(), w, tqt_xrootwin(), + NET::XAWMState | NET::WMWindowType); + NET::WindowType windowType = inf.windowType(NET::AllTypesMask); + + if ((windowType == NET::Normal || windowType == NET::Unknown) && + inf.mappingState() == NET::Visible) + { + TDEConfig twincfg( "twinrc", true ); // see in twin + twincfg.setGroup( "Windows" ); + if( twincfg.readBoolEntry( "ShowDesktopIsMinimizeAll", false )) + { + m_iconifiedList.clear(); + m_showingDesktop = false; + emit desktopShown(false); + } + else + { + m_activeWindow = w; + setShowDesktop(false); + } + } +} + +void KDesktop::slotWindowChanged(WId w, unsigned int dirty) +{ + bool m_showingDesktop = showDesktopState(); + + if (!m_showingDesktop) + { + return; + } + + if (dirty & NET::XAWMState) + { + NETWinInfo inf(tqt_xdisplay(), w, tqt_xrootwin(), + NET::XAWMState | NET::WMWindowType); + NET::WindowType windowType = inf.windowType(NET::AllTypesMask); + + if ((windowType == NET::Normal || windowType == NET::Unknown) && + inf.mappingState() == NET::Visible) + { + // a window was deiconified, abort the show desktop mode. + m_iconifiedList.clear(); + m_showingDesktop = false; + emit desktopShown(false); + } + } +} + +bool KDesktop::showDesktopState() +{ + return twinModule()->showingDesktop(); +} + +void KDesktop::toggleShowDesktop() +{ + setShowDesktop(!showDesktopState()); +} + +TDEActionCollection * KDesktop::actionCollection() +{ + if (!m_pIconView) + return 0; + return m_pIconView->actionCollection(); +} + +KURL KDesktop::url() const +{ + if (m_pIconView) + return m_pIconView->url(); + return KURL(); +} + +// ----------------------------------------------------------------------------- + +void KDesktop::slotConfigure() +{ + configure(); +} + +void KDesktop::configure() +{ + // re-read configuration and apply it + TDEGlobal::config()->reparseConfiguration(); + KDesktopSettings::self()->readConfig(); + + // If we have done start() already, then re-configure. + // Otherwise, start() will call initConfig anyway + if (!m_bInit) + { + initRoot(); + initConfig(); + KRootWm::self()->initConfig(); + } + + if (keys) + { + keys->readSettings(); + keys->updateConnections(); + } +} + +void KDesktop::slotSettingsChanged(int category) +{ + //kdDebug(1204) << "KDesktop::slotSettingsChanged" << endl; + if (category == TDEApplication::SETTINGS_PATHS) + { + kdDebug(1204) << "KDesktop::slotSettingsChanged SETTINGS_PATHS" << endl; + if (m_pIconView) + m_pIconView->recheckDesktopURL(); + } + else if (category == TDEApplication::SETTINGS_SHORTCUTS) + { + kdDebug(1204) << "KDesktop::slotSettingsChanged SETTINGS_SHORTCUTS" << endl; + keys->readSettings(); + keys->updateConnections(); + } +} + +void KDesktop::slotIconChanged(int group) +{ + if ( group == TDEIcon::Desktop ) + { + kdDebug(1204) << "KDesktop::slotIconChanged" << endl; + refresh(); + } +} + +void KDesktop::slotDatabaseChanged() +{ + //kdDebug(1204) << "KDesktop::slotDatabaseChanged" << endl; + if (m_bInit) // kded is done, now we can "start" for real + slotStart(); + if (m_pIconView && KSycoca::isChanged("mimetypes")) + m_pIconView->refreshMimeTypes(); +} + +void KDesktop::refresh() +{ + // George Staikos 3/14/01 + // This bit will just refresh the desktop and icons. Now I have code + // in KWin to do a complete refresh so this isn't really needed. + // I'll leave it in here incase the plan is changed again +#if 0 + m_bNeedRepaint |= 1; + updateWorkArea(); +#endif + kapp->dcopClient()->send( twin_name, "", "refresh()", TQString("")); + refreshIcons(); +} + +// ----------------------------------------------------------------------------- + +void KDesktop::slotSetVRoot() +{ + if (!m_pIconView) + return; + + if (KWin::windowInfo(winId()).mappingState() == NET::Withdrawn) { + TQTimer::singleShot(100, this, TQT_SLOT(slotSetVRoot())); + return; + } + + unsigned long rw = RootWindowOfScreen(ScreenOfDisplay(tqt_xdisplay(), tqt_xscreen())); + unsigned long vroot_data[1] = { m_pIconView->viewport()->winId() }; + static Atom vroot = XInternAtom(tqt_xdisplay(), "__SWM_VROOT", False); + + Window rootReturn, parentReturn, *children; + unsigned int numChildren; + Window top = winId(); + while (1) { + /*int ret = */XQueryTree(tqt_xdisplay(), top , &rootReturn, &parentReturn, + &children, &numChildren); + if (children) + XFree((char *)children); + if (parentReturn == rw) { + break; + } else + top = parentReturn; + } + if ( set_vroot ) + XChangeProperty(tqt_xdisplay(), top, vroot, XA_WINDOW, 32, + PropModeReplace, (unsigned char *)vroot_data, 1); + else + XDeleteProperty (tqt_xdisplay(), top, vroot); +} + +// ----------------------------------------------------------------------------- + +void KDesktop::slotShutdown() +{ + if ( m_pIconView ) + m_pIconView->saveIconPositions(); + if ( m_miniCli ) + m_miniCli->saveConfig(); +} + +// don't hide when someone presses Alt-F4 on us +void KDesktop::closeEvent(TQCloseEvent *e) +{ + e->ignore(); +} + +void KDesktop::desktopIconsAreaChanged(const TQRect &area, int screen) +{ + // hurra! kicker is alive + if ( m_waitForKicker ) m_waitForKicker->stop(); + + // -2: all screens + // -1: primary screen + // else: screen number + + if (screen <= -2) + screen = kdesktop_screen_number; + else if (screen == -1) + screen = kapp->desktop()->primaryScreen(); + + // This is pretty broken, mixes Xinerama and non-Xinerama multihead + // and generally doesn't seem to be required anyway => ignore screen. + if ( /*(screen == kdesktop_screen_number) &&*/ m_pIconView ) { + m_pIconView->updateWorkArea(area); + } +} + +void KDesktop::slotSwitchDesktops(int delta) +{ + if(m_bWheelSwitchesWorkspace && KWin::numberOfDesktops() > 1) + { + int newDesk, curDesk = KWin::currentDesktop(); + + if( (delta < 0 && m_eWheelDirection == Forward) || (delta > 0 && m_eWheelDirection == Reverse) ) + newDesk = curDesk % KWin::numberOfDesktops() + 1; + else + newDesk = ( KWin::numberOfDesktops() + curDesk - 2 ) % KWin::numberOfDesktops() + 1; + + KWin::setCurrentDesktop( newDesk ); + } +} + +void KDesktop::handleColorDropEvent(TQDropEvent * e) +{ + TDEPopupMenu popup; + popup.insertItem(SmallIconSet("colors"),i18n("Set as Primary Background Color"), 1); + popup.insertItem(SmallIconSet("colors"),i18n("Set as Secondary Background Color"), 2); + int result = popup.exec(e->pos()); + + TQColor c; + KColorDrag::decode(e, c); + switch (result) { + case 1: bgMgr->setColor(c, true); break; + case 2: bgMgr->setColor(c, false); break; + default: return; + } + bgMgr->setWallpaper(0,0); +} + +void KDesktop::handleImageDropEvent(TQDropEvent * e) +{ + TDEPopupMenu popup; + if ( m_pIconView ) + popup.insertItem(SmallIconSet("document-save"),i18n("&Save to Desktop..."), 1); + if ( ( m_pIconView && m_pIconView->maySetWallpaper() ) || m_pRootWidget ) + popup.insertItem(SmallIconSet("background"),i18n("Set as &Wallpaper"), 2); + popup.insertSeparator(); + popup.insertItem(SmallIconSet("cancel"), i18n("&Cancel")); + int result = popup.exec(e->pos()); + + if (result == 1) + { + bool ok = true; + TQString filename = KInputDialog::getText(TQString::null, i18n("Enter a name for the image below:"), TQString::null, &ok, m_pIconView); + + if (!ok) + { + return; + } + + if (filename.isEmpty()) + { + filename = i18n("image.png"); + } + else if (filename.right(4).lower() != ".png") + { + filename += ".png"; + } + + TQImage i; + TQImageDrag::decode(e, i); + KTempFile tmpFile(TQString::null, filename); + i.save(tmpFile.name(), "PNG"); + // We pass 0 as parent window because passing the desktop is not a good idea + KURL src; + src.setPath( tmpFile.name() ); + KURL dest( KDIconView::desktopURL() ); + dest.addPath( filename ); + TDEIO::NetAccess::copy( src, dest, 0 ); + tmpFile.unlink(); + } + else if (result == 2) + { + TQImage i; + TQImageDrag::decode(e, i); + KTempFile tmpFile(TDEGlobal::dirs()->saveLocation("wallpaper"), ".png"); + i.save(tmpFile.name(), "PNG"); + kdDebug(1204) << "KDesktop::contentsDropEvent " << tmpFile.name() << endl; + bgMgr->setWallpaper(tmpFile.name()); + } +} + +void KDesktop::slotNewWallpaper(const KURL &url) +{ + // This is called when a file containing an image is dropped + // (called by KonqOperations) + if ( url.isLocalFile() ) + bgMgr->setWallpaper( url.path() ); + else + { + // Figure out extension + TQString fileName = url.fileName(); + TQFileInfo fileInfo( fileName ); + TQString ext = fileInfo.extension(); + // Store tempfile in a place where it will still be available after a reboot + KTempFile tmpFile( TDEGlobal::dirs()->saveLocation("wallpaper"), "." + ext ); + KURL localURL; localURL.setPath( tmpFile.name() ); + // We pass 0 as parent window because passing the desktop is not a good idea + TDEIO::NetAccess::file_copy( url, localURL, -1, true /*overwrite*/ ); + bgMgr->setWallpaper( localURL.path() ); + } +} + +// for dcop interface backward compatibility +void KDesktop::logout() +{ + logout( TDEApplication::ShutdownConfirmDefault, + TDEApplication::ShutdownTypeNone ); +} + +void KDesktop::logout( TDEApplication::ShutdownConfirm confirm, + TDEApplication::ShutdownType sdtype ) +{ + if( !kapp->requestShutDown( confirm, sdtype ) ) + // this i18n string is also in kicker/applets/run/runapplet + KMessageBox::error( this, i18n("Could not log out properly.\nThe session manager cannot " + "be contacted. You can try to force a shutdown by pressing " + "Ctrl+Alt+Backspace; note, however, that your current session " + "will not be saved with a forced shutdown." ) ); +} + +void KDesktop::slotLogout() +{ + logout( TDEApplication::ShutdownConfirmDefault, + TDEApplication::ShutdownTypeDefault ); +} + +void KDesktop::slotLogoutNoCnf() +{ + logout( TDEApplication::ShutdownConfirmNo, + TDEApplication::ShutdownTypeNone ); +} + +void KDesktop::slotHaltNoCnf() +{ + logout( TDEApplication::ShutdownConfirmNo, + TDEApplication::ShutdownTypeHalt ); +} + +void KDesktop::slotRebootNoCnf() +{ + logout( TDEApplication::ShutdownConfirmNo, + TDEApplication::ShutdownTypeReboot ); +} + +void KDesktop::setVRoot( bool enable ) +{ + if ( enable == set_vroot ) + return; + + set_vroot = enable; + kdDebug(1204) << "setVRoot " << enable << endl; + KDesktopSettings::setSetVRoot( set_vroot ); + KDesktopSettings::writeConfig(); + slotSetVRoot(); +} + +void KDesktop::clearCommandHistory() +{ + if ( m_miniCli ) + m_miniCli->clearHistory(); +} + +void KDesktop::setIconsEnabled( bool enable ) +{ + if ( enable == m_bDesktopEnabled ) + return; + + m_bDesktopEnabled = enable; + kdDebug(1204) << "setIcons " << enable << endl; + KDesktopSettings::setDesktopEnabled( m_bDesktopEnabled ); + KDesktopSettings::writeConfig(); + if (!enable) { + delete m_pIconView; + m_pIconView = 0; + } + configure(); +} + +void KDesktop::desktopResized() +{ + resize(kapp->desktop()->size()); + + if ( m_pIconView ) + { + // the sequence of actions is important: + // remove all icons, resize desktop, tell kdiconview new iconsArea size + // tell kdiconview to reget all icons + m_pIconView->slotClear(); + m_pIconView->resize(kapp->desktop()->size()); + + // get new desktopIconsArea from kicker + TQByteArray data, result; + TQDataStream arg(data, IO_WriteOnly); + arg << kdesktop_screen_number; + TQCString replyType; + TQRect area; + + if ( kapp->dcopClient()->call(kicker_name, kicker_name, "desktopIconsArea(int)", + data, replyType, result, false, 2000) ) + { + TQDataStream res(result, IO_ReadOnly); + res >> area; + } + else + { + area = twinModule()->workArea(twinModule()->currentDesktop()); + } + + m_pIconView->updateWorkArea(area); + m_pIconView->startDirLister(); + } +} + +void KDesktop::switchDesktops( int delta ) +{ + bool old = m_bWheelSwitchesWorkspace; + m_bWheelSwitchesWorkspace = true; + slotSwitchDesktops(delta); + m_bWheelSwitchesWorkspace = old; +} + +bool KDesktop::event(TQEvent * e) +{ + if ( e->type() == TQEvent::WindowDeactivate) + { + if (m_pIconView) + m_pIconView->clearSelection(); + } + return TQWidget::event(e); +} + +TQPoint KDesktop::findPlaceForIcon( int column, int row ) +{ + if (m_pIconView) + return m_pIconView->findPlaceForIcon(column, row); + else + return TQPoint(-1, -1); +} + +void KDesktop::addIcon(const TQString & _url, int x, int y) +{ + addIcon( _url, TDEGlobalSettings::desktopPath(), x, y ); +} + +void KDesktop::addIcon(const TQString & _url, const TQString & _dest, int x, int y) +{ + TQString filename = _url.mid(_url.findRev('/') + 1); + + TQValueList files; + TDEIO::CopyInfo i; + i.uSource = KURL::fromPathOrURL( _url ); + i.uDest = KURL::fromPathOrURL( _dest ); + i.uDest.addPath( filename ); + files.append(i); + if (!TQFile::exists(i.uDest.prettyURL().replace("file://",TQString()))) { m_pIconView->slotAboutToCreate( TQPoint( x, y ), files ); + TDEIO::copy( i.uSource, i.uDest, false ); } + +// m_pIconView->addFuturePosition(filename, x, y); + // tqDebug("addIcon %s %s %d %d", _url.latin1(), _dest.latin1(), x, y); +// system(TQString("cp \"%1\" \"%2/%3\"").arg(KURL(_url).path()).arg(KURL(_dest).path()).arg(filename).latin1()); +// m_pIconView->update( _dest ); +} + +void KDesktop::removeIcon(const TQString &_url) +{ + if (_url.at(0) != '/') { + tqDebug("removeIcon with relative path not supported for now"); + return; + } + unlink(KURL(_url).path().latin1()); + TQString dest = _url.left(_url.findRev('/') + 1); + m_pIconView->update( dest ); +} + +#include "desktop.moc" diff --git a/kdesktop/init.cc b/kdesktop/init.cc deleted file mode 100644 index 6bf87f333..000000000 --- a/kdesktop/init.cc +++ /dev/null @@ -1,247 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 1999 David Faure - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -// for multihead -extern int kdesktop_screen_number; - - -/** - * Test if a directory exists, create otherwise - * @param _name full path of the directory - * @param _showMsg show a message box if we created the dir - * @return true if the dir was just created (e.g. so that we can populate it) - */ -static bool testDir( const TQString &_name ) -{ - DIR *dp; - dp = opendir( TQFile::encodeName(_name) ); - if ( dp == NULL ) - { - TQString m = _name; - if ( m.endsWith( "/" ) ) - m.truncate( m.length() - 1 ); - TQCString path = TQFile::encodeName(m); - - bool ok = ::mkdir( path, S_IRWXU ) == 0; - if ( !ok && errno == EEXIST ) { - int ret = KMessageBox::warningYesNo( 0, i18n("%1 is a file, but TDE needs it to be a directory; move it to %2.orig and create directory?").arg(m).arg(m), TQString::null, i18n("Move It"), i18n("Do Not Move") ); - if ( ret == KMessageBox::Yes ) { - if ( ::rename( path, path + ".orig" ) == 0 ) { - ok = ::mkdir( path, S_IRWXU ) == 0; - } else { - // foo.orig existed already. How likely is that? - ok = false; - } - } else { - return false; - } - } - if ( !ok ) - { - KMessageBox::sorry( 0, i18n( "Could not create directory %1; check for permissions or reconfigure the desktop to use another path." ).arg( m ) ); - return false; - } - return true; - } - else // exists already - { - closedir( dp ); - return false; - } -} - -/** - * Copy a standard .directory file to a user's directory - * @param fileName destination file name - * @param dir destination directory - * @param force if false, don't copy if destination file already exists - */ -static void copyDirectoryFile(const TQString &fileName, const TQString& dir, bool force) -{ - if (force || !TQFile::exists(dir + "/.directory")) { - TQString cmd = "cp "; - cmd += TDEProcess::quote(locate("data", TQString("kdesktop/") + fileName)); - cmd += " "; - cmd += TDEProcess::quote(dir+"/.directory"); - system( TQFile::encodeName(cmd) ); - } -} - -static void copyFile( const TQString& src, const TQString& dest ) -{ - TQCString cmd = "cp "; - cmd += TQFile::encodeName(TDEProcess::quote(src)); - cmd += " "; - cmd += TQFile::encodeName(TDEProcess::quote(dest)); - system( cmd ); -} - -static TQString realDesktopPath() -{ - TQString desktopPath = TDEGlobalSettings::desktopPath(); - if (kdesktop_screen_number != 0) { - TQString dn = "Desktop"; - dn += TQString::number(kdesktop_screen_number); - desktopPath.replace("Desktop", dn); - } - return desktopPath; -} - -/** - * Copy all links from DesktopLinks/ to the desktop, appropriately renamed - * (to the contents of the translated Name field) - */ -static void copyDesktopLinks() -{ - TDEConfig *config = kapp->config(); - config->setGroup("General"); - if (!config->readBoolEntry("CopyDesktopLinks", true)) - return; - - TQStringList list = - TDEGlobal::dirs()->findAllResources("appdata", "DesktopLinks/*", false, true); - - TQString desktopPath = realDesktopPath(); - - for (TQStringList::ConstIterator it = list.begin(); it != list.end(); it++) { - KDesktopFile desk( *it ); - if (desk.readBoolEntry("Hidden")) - continue; - copyFile( *it, desktopPath ); - } -} - -/** - * @return true if this is the first time - * kdesktop is run for the current release - * WARNING : call only once !!! (second call will always return false !) - */ -static bool isNewRelease() -{ - bool bNewRelease = false; - - int versionMajor = KDesktopSettings::kDEVersionMajor(); - int versionMinor = KDesktopSettings::kDEVersionMinor(); - int versionRelease = KDesktopSettings::kDEVersionRelease(); - - if( versionMajor < TDE_VERSION_MAJOR ) - bNewRelease = true; - else if( versionMinor < TDE_VERSION_MINOR ) - bNewRelease = true; - else if( versionRelease < TDE_VERSION_RELEASE ) - bNewRelease = true; - - if( bNewRelease ) { - KDesktopSettings::setKDEVersionMajor( TDE_VERSION_MAJOR ); - KDesktopSettings::setKDEVersionMinor( TDE_VERSION_MINOR ); - KDesktopSettings::setKDEVersionRelease( TDE_VERSION_RELEASE ); - KDesktopSettings::writeConfig(); - } - - return bNewRelease; -} - -/** - * Create, if necessary, some directories in user's .kde/, - * copy default .directory files there, as well as templates files. - * Called by kdesktop on startup. - */ -void testLocalInstallation() -{ - const bool newRelease = isNewRelease(); - - const TQString desktopPath = realDesktopPath(); - const bool emptyDesktop = testDir( desktopPath ); - - // Do not force copying that one (it would lose the icon positions) - copyDirectoryFile("directory.desktop", desktopPath, false); - - testDir( TDEGlobalSettings::autostartPath() ); - // we force the copying in case of a new release, to install new translations.... - copyDirectoryFile("directory.autostart", TDEGlobalSettings::autostartPath(), newRelease); - - if (emptyDesktop) - copyDesktopLinks(); - - // Take care of creating or updating trash.desktop - const TQString trashDir = TDEGlobal::dirs()->localxdgdatadir() + "Trash"; - const bool firstTimeWithNewTrash = !TQFile::exists( trashDir ); - const TQString trashDesktopPath = desktopPath + "/trash.desktop"; - const bool trashDesktopExists = TQFile::exists( trashDesktopPath ); - const bool installNewTrashi18n = newRelease && trashDesktopExists; // not if deleted by user - if ( emptyDesktop || firstTimeWithNewTrash || installNewTrashi18n ) { - TQString oldIcon, oldEmptyIcon; - if ( trashDesktopExists ) { - KDesktopFile trashDesktop( trashDesktopPath, true ); - oldIcon = trashDesktop.readIcon(); - oldEmptyIcon = trashDesktop.readEntry( "EmptyIcon" ); - } - copyFile( locate( "data", "kdesktop/directory.trash" ), trashDesktopPath ); - if ( trashDesktopExists ) { - KDesktopFile trashDesktop( trashDesktopPath ); - trashDesktop.writeEntry( "Icon", oldIcon ); - trashDesktop.writeEntry( "EmptyIcon", oldEmptyIcon ); - trashDesktop.sync(); - } - } - - if ( firstTimeWithNewTrash ) { // migrate pre-kde-3.4 trash contents - TQByteArray packedArgs; - TQDataStream stream( packedArgs, IO_WriteOnly ); - stream << (int)2; - TDEIO::Job* job = TDEIO::special( "trash:/", packedArgs ); - (void)TDEIO::NetAccess::synchronousRun( job, 0 ); - - // OK the only thing missing is to convert the icon position... - KSimpleConfig cfg( locateLocal("appdata", "IconPositions") ); - if ( cfg.hasGroup( "IconPosition::Trash" ) && !cfg.hasGroup( "IconPosition::trash.desktop" ) ) { - const TQMap entries = cfg.entryMap( "IconPosition::Trash" ); - cfg.setGroup( "IconPosition::trash.desktop" ); - for( TQMap::ConstIterator it = entries.begin(); it != entries.end(); ++it ) { - cfg.writeEntry( it.key(), it.data() ); - } - } - } -} - diff --git a/kdesktop/init.cpp b/kdesktop/init.cpp new file mode 100644 index 000000000..6bf87f333 --- /dev/null +++ b/kdesktop/init.cpp @@ -0,0 +1,247 @@ +/* This file is part of the KDE project + Copyright (C) 1999 David Faure + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +// for multihead +extern int kdesktop_screen_number; + + +/** + * Test if a directory exists, create otherwise + * @param _name full path of the directory + * @param _showMsg show a message box if we created the dir + * @return true if the dir was just created (e.g. so that we can populate it) + */ +static bool testDir( const TQString &_name ) +{ + DIR *dp; + dp = opendir( TQFile::encodeName(_name) ); + if ( dp == NULL ) + { + TQString m = _name; + if ( m.endsWith( "/" ) ) + m.truncate( m.length() - 1 ); + TQCString path = TQFile::encodeName(m); + + bool ok = ::mkdir( path, S_IRWXU ) == 0; + if ( !ok && errno == EEXIST ) { + int ret = KMessageBox::warningYesNo( 0, i18n("%1 is a file, but TDE needs it to be a directory; move it to %2.orig and create directory?").arg(m).arg(m), TQString::null, i18n("Move It"), i18n("Do Not Move") ); + if ( ret == KMessageBox::Yes ) { + if ( ::rename( path, path + ".orig" ) == 0 ) { + ok = ::mkdir( path, S_IRWXU ) == 0; + } else { + // foo.orig existed already. How likely is that? + ok = false; + } + } else { + return false; + } + } + if ( !ok ) + { + KMessageBox::sorry( 0, i18n( "Could not create directory %1; check for permissions or reconfigure the desktop to use another path." ).arg( m ) ); + return false; + } + return true; + } + else // exists already + { + closedir( dp ); + return false; + } +} + +/** + * Copy a standard .directory file to a user's directory + * @param fileName destination file name + * @param dir destination directory + * @param force if false, don't copy if destination file already exists + */ +static void copyDirectoryFile(const TQString &fileName, const TQString& dir, bool force) +{ + if (force || !TQFile::exists(dir + "/.directory")) { + TQString cmd = "cp "; + cmd += TDEProcess::quote(locate("data", TQString("kdesktop/") + fileName)); + cmd += " "; + cmd += TDEProcess::quote(dir+"/.directory"); + system( TQFile::encodeName(cmd) ); + } +} + +static void copyFile( const TQString& src, const TQString& dest ) +{ + TQCString cmd = "cp "; + cmd += TQFile::encodeName(TDEProcess::quote(src)); + cmd += " "; + cmd += TQFile::encodeName(TDEProcess::quote(dest)); + system( cmd ); +} + +static TQString realDesktopPath() +{ + TQString desktopPath = TDEGlobalSettings::desktopPath(); + if (kdesktop_screen_number != 0) { + TQString dn = "Desktop"; + dn += TQString::number(kdesktop_screen_number); + desktopPath.replace("Desktop", dn); + } + return desktopPath; +} + +/** + * Copy all links from DesktopLinks/ to the desktop, appropriately renamed + * (to the contents of the translated Name field) + */ +static void copyDesktopLinks() +{ + TDEConfig *config = kapp->config(); + config->setGroup("General"); + if (!config->readBoolEntry("CopyDesktopLinks", true)) + return; + + TQStringList list = + TDEGlobal::dirs()->findAllResources("appdata", "DesktopLinks/*", false, true); + + TQString desktopPath = realDesktopPath(); + + for (TQStringList::ConstIterator it = list.begin(); it != list.end(); it++) { + KDesktopFile desk( *it ); + if (desk.readBoolEntry("Hidden")) + continue; + copyFile( *it, desktopPath ); + } +} + +/** + * @return true if this is the first time + * kdesktop is run for the current release + * WARNING : call only once !!! (second call will always return false !) + */ +static bool isNewRelease() +{ + bool bNewRelease = false; + + int versionMajor = KDesktopSettings::kDEVersionMajor(); + int versionMinor = KDesktopSettings::kDEVersionMinor(); + int versionRelease = KDesktopSettings::kDEVersionRelease(); + + if( versionMajor < TDE_VERSION_MAJOR ) + bNewRelease = true; + else if( versionMinor < TDE_VERSION_MINOR ) + bNewRelease = true; + else if( versionRelease < TDE_VERSION_RELEASE ) + bNewRelease = true; + + if( bNewRelease ) { + KDesktopSettings::setKDEVersionMajor( TDE_VERSION_MAJOR ); + KDesktopSettings::setKDEVersionMinor( TDE_VERSION_MINOR ); + KDesktopSettings::setKDEVersionRelease( TDE_VERSION_RELEASE ); + KDesktopSettings::writeConfig(); + } + + return bNewRelease; +} + +/** + * Create, if necessary, some directories in user's .kde/, + * copy default .directory files there, as well as templates files. + * Called by kdesktop on startup. + */ +void testLocalInstallation() +{ + const bool newRelease = isNewRelease(); + + const TQString desktopPath = realDesktopPath(); + const bool emptyDesktop = testDir( desktopPath ); + + // Do not force copying that one (it would lose the icon positions) + copyDirectoryFile("directory.desktop", desktopPath, false); + + testDir( TDEGlobalSettings::autostartPath() ); + // we force the copying in case of a new release, to install new translations.... + copyDirectoryFile("directory.autostart", TDEGlobalSettings::autostartPath(), newRelease); + + if (emptyDesktop) + copyDesktopLinks(); + + // Take care of creating or updating trash.desktop + const TQString trashDir = TDEGlobal::dirs()->localxdgdatadir() + "Trash"; + const bool firstTimeWithNewTrash = !TQFile::exists( trashDir ); + const TQString trashDesktopPath = desktopPath + "/trash.desktop"; + const bool trashDesktopExists = TQFile::exists( trashDesktopPath ); + const bool installNewTrashi18n = newRelease && trashDesktopExists; // not if deleted by user + if ( emptyDesktop || firstTimeWithNewTrash || installNewTrashi18n ) { + TQString oldIcon, oldEmptyIcon; + if ( trashDesktopExists ) { + KDesktopFile trashDesktop( trashDesktopPath, true ); + oldIcon = trashDesktop.readIcon(); + oldEmptyIcon = trashDesktop.readEntry( "EmptyIcon" ); + } + copyFile( locate( "data", "kdesktop/directory.trash" ), trashDesktopPath ); + if ( trashDesktopExists ) { + KDesktopFile trashDesktop( trashDesktopPath ); + trashDesktop.writeEntry( "Icon", oldIcon ); + trashDesktop.writeEntry( "EmptyIcon", oldEmptyIcon ); + trashDesktop.sync(); + } + } + + if ( firstTimeWithNewTrash ) { // migrate pre-kde-3.4 trash contents + TQByteArray packedArgs; + TQDataStream stream( packedArgs, IO_WriteOnly ); + stream << (int)2; + TDEIO::Job* job = TDEIO::special( "trash:/", packedArgs ); + (void)TDEIO::NetAccess::synchronousRun( job, 0 ); + + // OK the only thing missing is to convert the icon position... + KSimpleConfig cfg( locateLocal("appdata", "IconPositions") ); + if ( cfg.hasGroup( "IconPosition::Trash" ) && !cfg.hasGroup( "IconPosition::trash.desktop" ) ) { + const TQMap entries = cfg.entryMap( "IconPosition::Trash" ); + cfg.setGroup( "IconPosition::trash.desktop" ); + for( TQMap::ConstIterator it = entries.begin(); it != entries.end(); ++it ) { + cfg.writeEntry( it.key(), it.data() ); + } + } + } +} + diff --git a/kdesktop/kcustommenu.cc b/kdesktop/kcustommenu.cc deleted file mode 100644 index 2e825c0d9..000000000 --- a/kdesktop/kcustommenu.cc +++ /dev/null @@ -1,111 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001 Waldo Bastian - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include -#include - -#include -#include -#include - -#include "kcustommenu.h" - -class KCustomMenu::KCustomMenuPrivate -{ -public: - TQMap entryMap; -}; - -KCustomMenu::KCustomMenu(const TQString &configfile, TQWidget *parent) - : TQPopupMenu(parent, "kcustom_menu") -{ - d = new KCustomMenuPrivate; - - TDEConfig cfg(configfile, true, false); - int count = cfg.readNumEntry("NrOfItems"); - for(int i = 0; i < count; i++) - { - TQString entry = cfg.readEntry(TQString("Item%1").arg(i+1)); - if (entry.isEmpty()) - continue; - - // Try KSycoca first. - KService::Ptr menuItem = KService::serviceByDesktopPath( entry ); - if (!menuItem) - menuItem = KService::serviceByDesktopName( entry ); - if (!menuItem) - menuItem = new KService( entry ); - - if (!menuItem->isValid()) - continue; - - insertMenuItem( menuItem, -1 ); - } - connect(this, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotActivated(int))); -} - -KCustomMenu::~KCustomMenu() -{ - delete d; -} - -void -KCustomMenu::slotActivated(int id) -{ - KService::Ptr s = d->entryMap[id]; - if (!s) - return; - kapp->startServiceByDesktopPath(s->desktopEntryPath()); -} - -// The following is copied from kicker's PanelServiceMenu -void -KCustomMenu::insertMenuItem(KService::Ptr & s, int nId, int nIndex/*= -1*/) -{ - TQString serviceName = s->name(); - - // item names may contain ampersands. To avoid them being converted - // to accelators, replace them with two ampersands. - serviceName.replace("&", "&&"); - - TQPixmap normal = TDEGlobal::instance()->iconLoader()->loadIcon(s->icon(), TDEIcon::Small, - 0, TDEIcon::DefaultState, 0L, true); - TQPixmap active = TDEGlobal::instance()->iconLoader()->loadIcon(s->icon(), TDEIcon::Small, - 0, TDEIcon::ActiveState, 0L, true); - // make sure they are not larger than 16x16 - if (normal.width() > 16 || normal.height() > 16) { - TQImage tmp = normal.convertToImage(); - tmp = tmp.smoothScale(16, 16); - normal.convertFromImage(tmp); - } - if (active.width() > 16 || active.height() > 16) { - TQImage tmp = active.convertToImage(); - tmp = tmp.smoothScale(16, 16); - active.convertFromImage(tmp); - } - - TQIconSet iconset; - iconset.setPixmap(normal, TQIconSet::Small, TQIconSet::Normal); - iconset.setPixmap(active, TQIconSet::Small, TQIconSet::Active); - - int newId = insertItem(iconset, serviceName, nId, nIndex); - d->entryMap.insert(newId, s); -} - -#include "kcustommenu.moc" diff --git a/kdesktop/kcustommenu.cpp b/kdesktop/kcustommenu.cpp new file mode 100644 index 000000000..2e825c0d9 --- /dev/null +++ b/kdesktop/kcustommenu.cpp @@ -0,0 +1,111 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Waldo Bastian + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include + +#include +#include +#include + +#include "kcustommenu.h" + +class KCustomMenu::KCustomMenuPrivate +{ +public: + TQMap entryMap; +}; + +KCustomMenu::KCustomMenu(const TQString &configfile, TQWidget *parent) + : TQPopupMenu(parent, "kcustom_menu") +{ + d = new KCustomMenuPrivate; + + TDEConfig cfg(configfile, true, false); + int count = cfg.readNumEntry("NrOfItems"); + for(int i = 0; i < count; i++) + { + TQString entry = cfg.readEntry(TQString("Item%1").arg(i+1)); + if (entry.isEmpty()) + continue; + + // Try KSycoca first. + KService::Ptr menuItem = KService::serviceByDesktopPath( entry ); + if (!menuItem) + menuItem = KService::serviceByDesktopName( entry ); + if (!menuItem) + menuItem = new KService( entry ); + + if (!menuItem->isValid()) + continue; + + insertMenuItem( menuItem, -1 ); + } + connect(this, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotActivated(int))); +} + +KCustomMenu::~KCustomMenu() +{ + delete d; +} + +void +KCustomMenu::slotActivated(int id) +{ + KService::Ptr s = d->entryMap[id]; + if (!s) + return; + kapp->startServiceByDesktopPath(s->desktopEntryPath()); +} + +// The following is copied from kicker's PanelServiceMenu +void +KCustomMenu::insertMenuItem(KService::Ptr & s, int nId, int nIndex/*= -1*/) +{ + TQString serviceName = s->name(); + + // item names may contain ampersands. To avoid them being converted + // to accelators, replace them with two ampersands. + serviceName.replace("&", "&&"); + + TQPixmap normal = TDEGlobal::instance()->iconLoader()->loadIcon(s->icon(), TDEIcon::Small, + 0, TDEIcon::DefaultState, 0L, true); + TQPixmap active = TDEGlobal::instance()->iconLoader()->loadIcon(s->icon(), TDEIcon::Small, + 0, TDEIcon::ActiveState, 0L, true); + // make sure they are not larger than 16x16 + if (normal.width() > 16 || normal.height() > 16) { + TQImage tmp = normal.convertToImage(); + tmp = tmp.smoothScale(16, 16); + normal.convertFromImage(tmp); + } + if (active.width() > 16 || active.height() > 16) { + TQImage tmp = active.convertToImage(); + tmp = tmp.smoothScale(16, 16); + active.convertFromImage(tmp); + } + + TQIconSet iconset; + iconset.setPixmap(normal, TQIconSet::Small, TQIconSet::Normal); + iconset.setPixmap(active, TQIconSet::Small, TQIconSet::Active); + + int newId = insertItem(iconset, serviceName, nId, nIndex); + d->entryMap.insert(newId, s); +} + +#include "kcustommenu.moc" diff --git a/kdesktop/kdesktop.kcfg b/kdesktop/kdesktop.kcfg index 53a1cc781..5df427c71 100644 --- a/kdesktop/kdesktop.kcfg +++ b/kdesktop/kdesktop.kcfg @@ -52,7 +52,7 @@ true - + @@ -64,9 +64,9 @@ false - + - + @@ -85,7 +85,7 @@ Forward - + @@ -190,7 +190,7 @@ - + @@ -199,14 +199,14 @@ true - + media/nfs_mounted,media/nfs_unmounted,media/hdd_mounted,media/hdd_unmounted,media/floppy_unmounted,media/cdrom_unmounted,media/floppy5_unmounted The device types which you do not want to see on the desktop. - + diff --git a/kdesktop/kdiconview.cc b/kdesktop/kdiconview.cc deleted file mode 100644 index 86737ce3c..000000000 --- a/kdesktop/kdiconview.cc +++ /dev/null @@ -1,2092 +0,0 @@ -/* 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 /