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

KIO

  • sources
  • kde-4.14
  • kdelibs
  • 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 
37 static 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 
60 QStringList KRecentDirs::list(const QString &fileClass)
61 {
62  QString key = fileClass;
63  QStringList result;
64  recentdirs_readList(key, result).sync();
65  return result;
66 }
67 
68 QString KRecentDirs::dir(const QString &fileClass)
69 {
70  const QStringList result = list(fileClass);
71  return result[0];
72 }
73 
74 void 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::readPathEntry
QString readPathEntry(const QString &pKey, const QString &aDefault) const
KConfigGroup::writePathEntry
void writePathEntry(const QString &pKey, const QString &path, WriteConfigFlags pFlags=Normal)
kglobalsettings.h
kconfig.h
KRecentDirs::add
void add(const QString &fileClass, const QString &directory)
Associates directory with fileClass.
Definition: krecentdirs.cpp:74
krecentdirs.h
KGlobal::config
KSharedConfigPtr config()
kglobal.h
QList::count
int count(const T &value) const
QList::append
void append(const T &value)
QList::isEmpty
bool isEmpty() const
QList::removeAll
int removeAll(const T &value)
ksharedconfig.h
QString
QStringList
KGlobalSettings::documentPath
static QString documentPath()
KConfigGroup
QString::mid
QString mid(int position, int n) const
KRecentDirs::dir
QString dir(const QString &fileClass)
Returns the most recently used directory accociated with this file-class.
Definition: krecentdirs.cpp:68
QLatin1String
QList::removeLast
void removeLast()
QString::length
int length() const
QList::prepend
void prepend(const T &value)
KConfigGroup::sync
void sync()
MAX_DIR_HISTORY
#define MAX_DIR_HISTORY
Definition: krecentdirs.cpp:35
KSharedConfig::openConfig
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, const char *resourceType="config")
recentdirs_readList
static KConfigGroup recentdirs_readList(QString &key, QStringList &result)
Definition: krecentdirs.cpp:37
kconfiggroup.h
KRecentDirs::list
QStringList list(const QString &fileClass)
Returns a list of directories associated with this file-class.
Definition: krecentdirs.cpp:60
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:53 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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