3
// "Desktop Options" Tab for KDesktop configuration
5
// (c) Martin R. Jones 1996
6
// (c) Bernd Wuebben 1998
9
// (c) Christian Tibirna 1998
10
// Port to KControl, split from Misc Tab, Port to KControl2
11
// (c) David Faure 1998
12
// Desktop menus, paths
13
// (c) David Faure 2000
17
#include <qcheckbox.h>
18
#include <qcombobox.h>
21
#include <qvgroupbox.h>
22
#include <qwhatsthis.h>
24
#include <dcopclient.h>
26
#include <kapplication.h>
27
#include <kcustommenueditor.h>
29
#include <kfileitem.h>
30
#include <kglobalsettings.h>
32
#include <klistview.h>
35
#include <kmessagebox.h>
36
#include <kmimetype.h>
37
#include <kstandarddirs.h>
39
#include <konq_defaults.h> // include default values directly from libkonq
40
#include <kurlrequester.h>
44
//-----------------------------------------------------------------------------
46
DesktopPathConfig::DesktopPathConfig(QWidget *parent, const char * )
47
: KCModule( parent, "kcmkonq" )
53
#define RO_LASTROW 4 // 3 paths + last row
57
QGridLayout *lay = new QGridLayout(this, RO_LASTROW+1, RO_LASTCOL+1,
58
0, KDialog::spacingHint());
60
lay->setRowStretch(RO_LASTROW,10); // last line grows
62
lay->setColStretch(0,0);
63
lay->setColStretch(1,0);
64
lay->setColStretch(2,10);
67
setQuickHelp( i18n("<h1>Paths</h1>\n"
68
"This module allows you to choose where in the filesystem the "
69
"files on your desktop should be stored.\n"
70
"Use the \"What's This?\" (Shift+F1) to get help on specific options."));
74
tmpLabel = new QLabel(i18n("Des&ktop path:"), this);
75
lay->addWidget(tmpLabel, row, 0);
76
urDesktop = new KURLRequester(this);
77
urDesktop->setMode( KFile::Directory );
78
tmpLabel->setBuddy( urDesktop );
79
lay->addMultiCellWidget(urDesktop, row, row, 1, RO_LASTCOL);
80
connect(urDesktop, SIGNAL(textChanged(const QString &)), this, SLOT(changed()));
81
QString wtstr = i18n("This folder contains all the files"
82
" which you see on your desktop. You can change the location of this"
83
" folder if you want to, and the contents will move automatically"
84
" to the new location as well.");
85
QWhatsThis::add( tmpLabel, wtstr );
86
QWhatsThis::add( urDesktop, wtstr );
89
tmpLabel = new QLabel(i18n("A&utostart path:"), this);
90
lay->addWidget(tmpLabel, row, 0);
91
urAutostart = new KURLRequester(this);
92
urAutostart->setMode( KFile::Directory );
93
tmpLabel->setBuddy( urAutostart );
94
lay->addMultiCellWidget(urAutostart, row, row, 1, RO_LASTCOL);
95
connect(urAutostart, SIGNAL(textChanged(const QString &)), this, SLOT(changed()));
96
wtstr = i18n("This folder contains applications or"
97
" links to applications (shortcuts) that you want to have started"
98
" automatically whenever KDE starts. You can change the location of this"
99
" folder if you want to, and the contents will move automatically"
100
" to the new location as well.");
101
QWhatsThis::add( tmpLabel, wtstr );
102
QWhatsThis::add( urAutostart, wtstr );
105
tmpLabel = new QLabel(i18n("D&ocuments path:"), this);
106
lay->addWidget(tmpLabel, row, 0);
107
urDocument = new KURLRequester(this);
108
urDocument->setMode( KFile::Directory );
109
tmpLabel->setBuddy( urDocument );
110
lay->addMultiCellWidget(urDocument, row, row, 1, RO_LASTCOL);
111
connect(urDocument, SIGNAL(textChanged(const QString &)), this, SLOT(changed()));
112
wtstr = i18n("This folder will be used by default to "
113
"load or save documents from or to.");
114
QWhatsThis::add( tmpLabel, wtstr );
115
QWhatsThis::add( urDocument, wtstr );
118
Q_ASSERT( row == RO_LASTROW-1 ); // if it fails here, check the row++ and RO_LASTROW above
123
void DesktopPathConfig::load()
128
void DesktopPathConfig::load( bool useDefaults )
130
KConfig config("kdeglobals", true, false);
132
config.setReadDefaults( useDefaults );
134
config.setGroup("Paths");
135
urDesktop->setURL( config.readPathEntry( "Desktop" , KGlobalSettings::desktopPath() ));
136
urAutostart->setURL( config.readPathEntry( "Autostart" , KGlobalSettings::autostartPath() ));
137
urDocument->setURL( config.readPathEntry( "Documents", KGlobalSettings::documentPath() ));
139
emit changed( useDefaults );
142
void DesktopPathConfig::defaults()
147
void DesktopPathConfig::save()
149
KConfig *config = KGlobal::config();
150
KConfigGroupSaver cgs( config, "Paths" );
152
bool pathChanged = false;
153
bool autostartMoved = false;
156
desktopURL.setPath( KGlobalSettings::desktopPath() );
158
newDesktopURL.setPath(urDesktop->url());
161
autostartURL.setPath( KGlobalSettings::autostartPath() );
162
KURL newAutostartURL;
163
newAutostartURL.setPath(urAutostart->url());
166
documentURL.setPath( KGlobalSettings::documentPath() );
168
newDocumentURL.setPath(urDocument->url());
170
if ( !newDesktopURL.equals( desktopURL, true ) )
172
// Test which other paths were inside this one (as it is by default)
173
// and for each, test where it should go.
174
// * Inside destination -> let them be moved with the desktop (but adjust name if necessary)
175
// * Not inside destination -> move first
177
kdDebug() << "desktopURL=" << desktopURL.url() << endl;
178
QString urlDesktop = urDesktop->url();
179
if ( !urlDesktop.endsWith( "/" ))
182
if ( desktopURL.isParentOf( autostartURL ) )
184
kdDebug() << "Autostart is on the desktop" << endl;
186
// Either the Autostart field wasn't changed (-> need to update it)
187
if ( newAutostartURL.equals( autostartURL, true ) )
189
// Hack. It could be in a subdir inside desktop. Hmmm... Argl.
190
urAutostart->setURL( urlDesktop + "Autostart/" );
191
kdDebug() << "Autostart is moved with the desktop" << endl;
192
autostartMoved = true;
194
// or it has been changed (->need to move it from here)
197
KURL futureAutostartURL;
198
futureAutostartURL.setPath( urlDesktop + "Autostart/" );
199
if ( newAutostartURL.equals( futureAutostartURL, true ) )
200
autostartMoved = true;
202
autostartMoved = moveDir( KURL( KGlobalSettings::autostartPath() ), KURL( urAutostart->url() ), i18n("Autostart") );
206
if ( moveDir( KURL( KGlobalSettings::desktopPath() ), KURL( urlDesktop ), i18n("Desktop") ) )
208
// config->writeEntry( "Desktop", urDesktop->url());
209
config->writePathEntry( "Desktop", urlDesktop, true, true );
214
if ( !newAutostartURL.equals( autostartURL, true ) )
217
autostartMoved = moveDir( KURL( KGlobalSettings::autostartPath() ), KURL( urAutostart->url() ), i18n("Autostart") );
220
// config->writeEntry( "Autostart", Autostart->url());
221
config->writePathEntry( "Autostart", urAutostart->url(), true, true );
226
if ( !newDocumentURL.equals( documentURL, true ) )
229
QString path = urDocument->url();
230
if (!QDir(path).exists())
232
if (!KStandardDirs::makeDir(path))
234
KMessageBox::sorry(this, KIO::buildErrorString(KIO::ERR_COULD_NOT_MKDIR, path));
235
urDocument->setURL(documentURL.path());
242
config->writePathEntry( "Documents", path, true, true );
251
kdDebug() << "DesktopPathConfig::save sending message SettingsChanged" << endl;
252
KIPC::sendMessageAll(KIPC::SettingsChanged, KApplication::SETTINGS_PATHS);
255
// Tell kdesktop about the new config file
256
if ( !kapp->dcopClient()->isAttached() )
257
kapp->dcopClient()->attach();
260
int konq_screen_number = KApplication::desktop()->primaryScreen();
262
if (konq_screen_number == 0)
263
appname = "kdesktop";
265
appname.sprintf("kdesktop-screen-%d", konq_screen_number);
266
kapp->dcopClient()->send( appname, "KDesktopIface", "configure()", data );
269
bool DesktopPathConfig::moveDir( const KURL & src, const KURL & dest, const QString & type )
271
if (!src.isLocalFile() || !dest.isLocalFile())
274
// Ask for confirmation before moving the files
275
if ( KMessageBox::questionYesNo( this, i18n("The path for '%1' has been changed;\ndo you want the files to be moved from '%2' to '%3'?").
276
arg(type).arg(src.path()).arg(dest.path()), i18n("Confirmation Required"),i18n("Move"),KStdGuiItem::cancel() )
277
== KMessageBox::Yes )
279
bool destExists = QFile::exists(dest.path());
284
KIO::ListJob* job = KIO::listDir( src );
285
connect( job, SIGNAL( entries( KIO::Job *, const KIO::UDSEntryList& ) ),
286
this, SLOT( slotEntries( KIO::Job *, const KIO::UDSEntryList& ) ) );
296
KIO::Job * job = KIO::move( src, dest );
297
connect( job, SIGNAL( result( KIO::Job * ) ), this, SLOT( slotResult( KIO::Job * ) ) );
302
kdDebug() << "DesktopPathConfig::slotResult returning " << m_ok << endl;
306
void DesktopPathConfig::slotEntries( KIO::Job * job, const KIO::UDSEntryList& list)
310
job->showErrorDialog(this);
314
KIO::UDSEntryListConstIterator it = list.begin();
315
KIO::UDSEntryListConstIterator end = list.end();
316
for (; it != end; ++it)
318
KFileItem file(*it, m_copyFromSrc, true, true);
319
if (file.url() == m_copyFromSrc || file.url().fileName() == "..")
324
KIO::Job * moveJob = KIO::move( file.url(), m_copyToDest );
325
connect( moveJob, SIGNAL( result( KIO::Job * ) ), this, SLOT( slotResult( KIO::Job * ) ) );
331
void DesktopPathConfig::slotResult( KIO::Job * job )
335
if ( job->error() != KIO::ERR_DOES_NOT_EXIST )
337
// If the source doesn't exist, no wonder we couldn't move the dir.
338
// In that case, trust the user and set the new setting in any case.
340
job->showErrorDialog(this);
345
#include "rootopts.moc"