2 Copyright (c) 2003 Dirk Mueller <mueller@kde.org>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include <kstandarddirs.h>
27 #include <ksharedconfig.h>
28 #include <kiconloader.h>
29 #include <kfiledialog.h>
30 #include <kurlrequester.h>
33 #include <kapplication.h>
34 #include <ktoolinvocation.h>
36 #include "plugin_paths.h"
38 static QDateTime
lastChanged( const QString
&dir
)
40 QDateTime t
= QFileInfo( dir
).lastModified();
43 const QStringList subdirs
= QDir( dir
).entryList();
44 for( QStringList::ConstIterator it
= subdirs
.constBegin();
45 it
!= subdirs
.constEnd();
48 if( *it
== "." || *it
== ".." )
50 QDateTime t2
= lastChanged( *it
);
51 if( !t2
.isNull() && t2
> t
)
57 static bool checkSearchPathTimestamps( const QStringList
&paths
, const QStringList
×tamps
)
59 QStringList currentTimestamps
;
61 QStringList::ConstIterator t
= timestamps
.constBegin();
62 for( QStringList::ConstIterator it
= paths
.constBegin();
63 it
!= paths
.constEnd();
66 QDateTime current
= lastChanged( *it
);
67 // store non-existent directory as "N" string rather than empty string, KConfig
68 // has a bug with storing a list of empty items
69 if( *t
== "N" ? !current
.isNull() : current
!= QDateTime::fromString( *t
, Qt::ISODate
))
71 currentTimestamps
.append( current
.isNull() ? "N" : current
.toString( Qt::ISODate
));
75 KConfig
config("kcmnspluginrc");
76 KConfigGroup
cg(&config
, "Misc");
77 cg
.writeEntry( "lastSearchPaths", paths
);
78 cg
.writeEntry( "lastSearchTimestamps", currentTimestamps
);
86 KDE_EXPORT
void kcminit_nsplugin()
88 KConfigGroup
config(KSharedConfig::openConfig( "kcmnspluginrc", KConfig::NoGlobals
), "Misc");
89 if( true ) // I don't think this needs to be configurable now
92 QStringList searchPaths
= getSearchPaths();
93 QStringList lastSearchPaths
= config
.readEntry( "lastSearchPaths", QStringList());
94 QStringList lastTimestamps
= config
.readEntry ( "lastSearchTimestamps", QStringList());
95 if( searchPaths
!= lastSearchPaths
|| lastTimestamps
.count() != lastSearchPaths
.count())
96 { // count changed, set empty timestamps, still call checkSearchPathTimestamps()
97 // in order to save the current timestamps for the next time
98 lastSearchPaths
= searchPaths
;
99 lastTimestamps
.clear();
101 i
< searchPaths
.count();
103 lastTimestamps
.append( "N" );
106 if( checkSearchPathTimestamps( lastSearchPaths
, lastTimestamps
))
109 KToolInvocation::kdeinitExec("nspluginscan");