• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kio/kfile
 

kio/kfile

krecentdirs.cpp
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 <ksimpleconfig.h>
00030 #include <kstandarddirs.h>
00031 #include <kglobalsettings.h>
00032 
00033 #define MAX_DIR_HISTORY 3
00034 
00035 static void recentdirs_done(KConfig *config)
00036 {
00037    if (config == KGlobal::config())
00038    {
00039       config->sync();
00040    }
00041    else
00042    {
00043       delete config;
00044    }
00045 }
00046 
00047 static KConfig *recentdirs_readList(TQString &key, TQStringList &result, bool readOnly)
00048 {
00049    KConfig *config;
00050    if ((key.length() < 2) || (key[0] != ':'))
00051      key = ":default";
00052    if (key[1] == ':') 
00053    {
00054       key = key.mid(2);
00055       config = new KSimpleConfig(TQString::fromLatin1("krecentdirsrc"), readOnly);
00056    }
00057    else
00058    {
00059       key = key.mid(1);
00060       config = KGlobal::config();
00061       config->setGroup(TQString::fromLatin1("Recent Dirs"));
00062    }
00063 
00064    result=config->readPathListEntry(key);
00065    if (result.isEmpty())
00066    {
00067       result.append(KGlobalSettings::documentPath());
00068    }
00069    return config;
00070 }
00071 
00072 TQStringList KRecentDirs::list(const TQString &fileClass)
00073 {
00074    TQString key = fileClass;
00075    TQStringList result;
00076    recentdirs_done(recentdirs_readList(key, result, true));
00077    return result;
00078 }
00079     
00080 TQString KRecentDirs::dir(const TQString &fileClass)
00081 {
00082    TQStringList result = list(fileClass);
00083    return result[0];
00084 }
00085 
00086 void KRecentDirs::add(const TQString &fileClass, const TQString &directory)
00087 {
00088    TQString key = fileClass;
00089    TQStringList result;
00090    KConfig *config = recentdirs_readList(key, result, false);
00091    // make sure the dir is first in history
00092    result.remove(directory);
00093    result.prepend(directory);
00094    while(result.count() > MAX_DIR_HISTORY)
00095       result.remove(result.fromLast());
00096    config->writePathEntry(key, result);
00097    recentdirs_done(config);
00098 }
00099 

kio/kfile

Skip menu "kio/kfile"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kio/kfile

Skip menu "kio/kfile"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kio/kfile by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |