• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KIO

krecentdirs.cpp

Go to the documentation of this file.
00001 /* -*- c++ -*-
00002  * Copyright (C)2000 Waldo Bastian <bastian@kde.org>
00003  *
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  *
00015  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00016  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00018  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00019  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00020  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00021  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00022  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00023  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00024  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00025  * SUCH DAMAGE.
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    // make sure the dir is first in history
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 

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal