KIO
krecentdirs.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <krecentdirs.h>
00029 #include <kconfig.h>
00030 #include <kconfiggroup.h>
00031 #include <ksharedconfig.h>
00032 #include <kstandarddirs.h>
00033 #include <kglobalsettings.h>
00034
00035 #define MAX_DIR_HISTORY 3
00036
00037 static KConfigGroup recentdirs_readList(QString &key, QStringList &result)
00038 {
00039 KConfigGroup cg(KGlobal::config(), QLatin1String("Recent Dirs"));
00040 if ((key.length() < 2) || (key[0] != ':'))
00041 key = ":default";
00042 if (key[1] == ':')
00043 {
00044 key = key.mid(2);
00045 cg = KConfigGroup(KSharedConfig::openConfig(QLatin1String("krecentdirsrc")), QString());
00046 }
00047 else
00048 {
00049 key = key.mid(1);
00050 }
00051
00052 result=cg.readPathEntry(key, QStringList());
00053 if (result.isEmpty())
00054 {
00055 result.append(KGlobalSettings::documentPath());
00056 }
00057 return cg;
00058 }
00059
00060 QStringList KRecentDirs::list(const QString &fileClass)
00061 {
00062 QString key = fileClass;
00063 QStringList result;
00064 recentdirs_readList(key, result).sync();
00065 return result;
00066 }
00067
00068 QString KRecentDirs::dir(const QString &fileClass)
00069 {
00070 const QStringList result = list(fileClass);
00071 return result[0];
00072 }
00073
00074 void KRecentDirs::add(const QString &fileClass, const QString &directory)
00075 {
00076 QString key = fileClass;
00077 QStringList result;
00078 KConfigGroup config = recentdirs_readList(key, result);
00079
00080 result.removeAll(directory);
00081 result.prepend(directory);
00082 while(result.count() > MAX_DIR_HISTORY)
00083 result.removeLast();
00084 config.writePathEntry(key, result);
00085 config.sync();
00086 }
00087