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

tdeio/tdefile

  • tdeio
  • tdefile
tderecentdirs.cpp
1 /*
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 <tderecentdirs.h>
29 #include <ksimpleconfig.h>
30 #include <kstandarddirs.h>
31 #include <tdeglobalsettings.h>
32 
33 #define MAX_DIR_HISTORY 3
34 
35 static void recentdirs_done(TDEConfig *config)
36 {
37  if (config == TDEGlobal::config())
38  {
39  config->sync();
40  }
41  else
42  {
43  delete config;
44  }
45 }
46 
47 static TDEConfig *recentdirs_readList(TQString &key, TQStringList &result, bool readOnly)
48 {
49  TDEConfig *config;
50  if ((key.length() < 2) || (key[0] != ':'))
51  key = ":default";
52  if (key[1] == ':')
53  {
54  key = key.mid(2);
55  config = new KSimpleConfig(TQString::fromLatin1("tderecentdirsrc"), readOnly);
56  }
57  else
58  {
59  key = key.mid(1);
60  config = TDEGlobal::config();
61  config->setGroup(TQString::fromLatin1("Recent Dirs"));
62  }
63 
64  result=config->readPathListEntry(key);
65  if (result.isEmpty())
66  {
67  result.append(TDEGlobalSettings::documentPath());
68  }
69  return config;
70 }
71 
72 TQStringList TDERecentDirs::list(const TQString &fileClass)
73 {
74  TQString key = fileClass;
75  TQStringList result;
76  recentdirs_done(recentdirs_readList(key, result, true));
77  return result;
78 }
79 
80 TQString TDERecentDirs::dir(const TQString &fileClass)
81 {
82  TQStringList result = list(fileClass);
83  return result[0];
84 }
85 
86 void TDERecentDirs::add(const TQString &fileClass, const TQString &directory)
87 {
88  TQString key = fileClass;
89  TQStringList result;
90  TDEConfig *config = recentdirs_readList(key, result, false);
91  // make sure the dir is first in history
92  result.remove(directory);
93  result.prepend(directory);
94  while(result.count() > MAX_DIR_HISTORY)
95  result.remove(result.fromLast());
96  config->writePathEntry(key, result);
97  recentdirs_done(config);
98 }
99 
TDERecentDirs::list
static TQStringList list(const TQString &fileClass)
Returns a list of directories associated with this file-class.
Definition: tderecentdirs.cpp:72
TDERecentDirs::dir
static TQString dir(const TQString &fileClass)
Returns the most recently used directory accociated with this file-class.
Definition: tderecentdirs.cpp:80
TDERecentDirs::add
static void add(const TQString &fileClass, const TQString &directory)
Associates directory with fileClass.
Definition: tderecentdirs.cpp:86

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.9.1
This website is maintained by Timothy Pearson.