• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdefile
 

tdeio/tdefile

tderecentdirs.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 <tderecentdirs.h>
00029 #include <ksimpleconfig.h>
00030 #include <kstandarddirs.h>
00031 #include <tdeglobalsettings.h>
00032 
00033 #define MAX_DIR_HISTORY 3
00034 
00035 static void recentdirs_done(TDEConfig *config)
00036 {
00037    if (config == TDEGlobal::config())
00038    {
00039       config->sync();
00040    }
00041    else
00042    {
00043       delete config;
00044    }
00045 }
00046 
00047 static TDEConfig *recentdirs_readList(TQString &key, TQStringList &result, bool readOnly)
00048 {
00049    TDEConfig *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("tderecentdirsrc"), readOnly);
00056    }
00057    else
00058    {
00059       key = key.mid(1);
00060       config = TDEGlobal::config();
00061       config->setGroup(TQString::fromLatin1("Recent Dirs"));
00062    }
00063 
00064    result=config->readPathListEntry(key);
00065    if (result.isEmpty())
00066    {
00067       result.append(TDEGlobalSettings::documentPath());
00068    }
00069    return config;
00070 }
00071 
00072 TQStringList TDERecentDirs::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 TDERecentDirs::dir(const TQString &fileClass)
00081 {
00082    TQStringList result = list(fileClass);
00083    return result[0];
00084 }
00085 
00086 void TDERecentDirs::add(const TQString &fileClass, const TQString &directory)
00087 {
00088    TQString key = fileClass;
00089    TQStringList result;
00090    TDEConfig *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 

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdefile by doxygen 1.7.1
This website is maintained by Timothy Pearson.