Fix crash if key bindings specified in profile cannot be found. Improve
[personal-kdebase.git] / apps / nsplugins / kcm_nsplugins.cpp
blob8d7e99d211b598b927aee757ce5c1bb4aae1aefb
1 /*
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.
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <unistd.h>
23 #include <QRegExp>
24 #include <QLayout>
25 #include <kstandarddirs.h>
26 #include <klocale.h>
27 #include <ksharedconfig.h>
28 #include <kiconloader.h>
29 #include <kfiledialog.h>
30 #include <kurlrequester.h>
31 #include <kdebug.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();
41 if( t.isNull())
42 return t;
43 const QStringList subdirs = QDir( dir ).entryList();
44 for( QStringList::ConstIterator it = subdirs.constBegin();
45 it != subdirs.constEnd();
46 ++it )
48 if( *it == "." || *it == ".." )
49 continue;
50 QDateTime t2 = lastChanged( *it );
51 if( !t2.isNull() && t2 > t )
52 t = t2;
54 return t;
57 static bool checkSearchPathTimestamps( const QStringList &paths, const QStringList &timestamps )
59 QStringList currentTimestamps;
60 bool changed = false;
61 QStringList::ConstIterator t = timestamps.constBegin();
62 for( QStringList::ConstIterator it = paths.constBegin();
63 it != paths.constEnd();
64 ++it, ++t )
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 ))
70 changed = true;
71 currentTimestamps.append( current.isNull() ? "N" : current.toString( Qt::ISODate ));
73 if( changed )
75 KConfig config("kcmnspluginrc");
76 KConfigGroup cg(&config, "Misc");
77 cg.writeEntry( "lastSearchPaths", paths );
78 cg.writeEntry( "lastSearchTimestamps", currentTimestamps );
79 return true;
81 return false;
84 extern "C"
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
91 bool update = false;
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();
100 for( int i = 0;
101 i < searchPaths.count();
102 ++i )
103 lastTimestamps.append( "N" );
104 update = true;
106 if( checkSearchPathTimestamps( lastSearchPaths, lastTimestamps ))
107 update = true;
108 if( update )
109 KToolInvocation::kdeinitExec("nspluginscan");