• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KIO

  • kio
  • kfile
krecentdirs.cpp
Go to the documentation of this file.
1/* -*- c++ -*-
2 * Copyright (C)2000 Waldo Bastian <bastian@kde.org>
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 */
28#include "krecentdirs.h"
29#include <kconfig.h>
30#include <kconfiggroup.h>
31#include <ksharedconfig.h>
32#include <kglobal.h>
33#include <kglobalsettings.h>
34
35#define MAX_DIR_HISTORY 3
36
37static KConfigGroup recentdirs_readList(QString &key, QStringList &result)
38{
39 KConfigGroup cg(KGlobal::config(), QLatin1String("Recent Dirs"));
40 if ((key.length() < 2) || (key[0] != ':'))
41 key = ":default";
42 if (key[1] == ':')
43 {
44 key = key.mid(2);
45 cg = KConfigGroup(KSharedConfig::openConfig(QLatin1String("krecentdirsrc")), QString());
46 }
47 else
48 {
49 key = key.mid(1);
50 }
51
52 result=cg.readPathEntry(key, QStringList());
53 if (result.isEmpty())
54 {
55 result.append(KGlobalSettings::documentPath());
56 }
57 return cg;
58}
59
60QStringList KRecentDirs::list(const QString &fileClass)
61{
62 QString key = fileClass;
63 QStringList result;
64 recentdirs_readList(key, result).sync();
65 return result;
66}
67
68QString KRecentDirs::dir(const QString &fileClass)
69{
70 const QStringList result = list(fileClass);
71 return result[0];
72}
73
74void KRecentDirs::add(const QString &fileClass, const QString &directory)
75{
76 QString key = fileClass;
77 QStringList result;
78 KConfigGroup config = recentdirs_readList(key, result);
79 // make sure the dir is first in history
80 result.removeAll(directory);
81 result.prepend(directory);
82 while(result.count() > MAX_DIR_HISTORY)
83 result.removeLast();
84 config.writePathEntry(key, result);
85 config.sync();
86}
87
KConfigGroup
KConfigGroup::readPathEntry
QString readPathEntry(const char *key, const QString &aDefault) const
KConfigGroup::sync
void sync()
KGlobalSettings::documentPath
static QString documentPath()
KSharedConfig::openConfig
static KSharedConfig::Ptr openConfig(const KComponentData &componentData, const QString &fileName=QString(), OpenFlags mode=FullConfig, const char *resourceType="config")
kconfig.h
kconfiggroup.h
kglobal.h
kglobalsettings.h
MAX_DIR_HISTORY
#define MAX_DIR_HISTORY
Definition: krecentdirs.cpp:35
recentdirs_readList
static KConfigGroup recentdirs_readList(QString &key, QStringList &result)
Definition: krecentdirs.cpp:37
krecentdirs.h
ksharedconfig.h
KGlobal::config
KSharedConfigPtr config()
KRecentDirs::dir
QString dir(const QString &fileClass)
Returns the most recently used directory accociated with this file-class.
Definition: krecentdirs.cpp:68
KRecentDirs::list
QStringList list(const QString &fileClass)
Returns a list of directories associated with this file-class.
Definition: krecentdirs.cpp:60
KRecentDirs::add
void add(const QString &fileClass, const QString &directory)
Associates directory with fileClass.
Definition: krecentdirs.cpp:74
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal