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

tdeio/tdefile

  • tdeio
  • tdefile
tderecentdocument.cpp
1/*
2 * Copyright (C)2000 Daniel M. Duley <mosfet@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 <tderecentdocument.h>
29#include <ksimpleconfig.h>
30#include <tdestandarddirs.h>
31#include <tdeapplication.h>
32#include <kurl.h>
33#include <kdebug.h>
34#include <kmimetype.h>
35#include <kdesktopfile.h>
36#include <tqdir.h>
37#include <tqfileinfo.h>
38#include <tqtextstream.h>
39#include <tqstringlist.h>
40#include <tqregexp.h>
41
42#include <sys/types.h>
43#include <utime.h>
44
45TQString TDERecentDocument::recentDocumentDirectory()
46{
47 // need to change this path, not sure where
48 return locateLocal("data", TQString::fromLatin1("RecentDocuments/"));
49}
50
51TQStringList TDERecentDocument::recentDocuments()
52{
53 TQDir d(recentDocumentDirectory(), "*.desktop", TQDir::Time,
54 TQDir::Files | TQDir::Readable | TQDir::Hidden);
55
56 if (!d.exists())
57 d.mkdir(recentDocumentDirectory());
58
59 TQStringList list = d.entryList();
60 TQStringList fullList;
61
62 for (TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
63 TQString pathDesktop = d.absFilePath( *it );
64 KDesktopFile tmpDesktopFile( pathDesktop, false);
65 KURL urlDesktopFile(tmpDesktopFile.readURL());
66 if( urlDesktopFile.isLocalFile() && !TQFile(urlDesktopFile.path()).exists())
67 d.remove(pathDesktop);
68 else
69 fullList.append( pathDesktop );
70 }
71
72 return fullList;
73}
74
75void TDERecentDocument::add(const KURL& url)
76{
77 TDERecentDocument::add(url, tqApp->argv()[0]); // ### argv[0] might not match the service filename!
78}
79
80void TDERecentDocument::add(const KURL& url, const TQString& desktopEntryName)
81{
82 if ( url.isLocalFile() && !TDEGlobal::dirs()->relativeLocation("tmp", url.path()).startsWith("/"))
83 return;
84
85 TQString openStr = url.url();
86 openStr.replace( TQRegExp("\\$"), "$$" ); // Desktop files with type "Link" are $-variable expanded
87
88 kdDebug(250) << "TDERecentDocument::add for " << openStr << endl;
89 TDEConfig *config = TDEGlobal::config();
90 TQString oldGrp = config->group();
91 config->setGroup(TQString::fromLatin1("RecentDocuments"));
92 bool useRecent = config->readBoolEntry(TQString::fromLatin1("UseRecent"), true);
93 int maxEntries = config->readNumEntry(TQString::fromLatin1("MaxEntries"), 10);
94
95 config->setGroup(oldGrp);
96 if(!useRecent)
97 return;
98
99 TQString path = recentDocumentDirectory();
100
101 TQString dStr = path + url.fileName();
102
103 TQString ddesktop = dStr + TQString::fromLatin1(".desktop");
104
105 int i=1;
106 // check for duplicates
107 while(TQFile::exists(ddesktop)){
108 // see if it points to the same file and application
109 KSimpleConfig tmp(ddesktop);
110 tmp.setDesktopGroup();
111 if(tmp.readEntry(TQString::fromLatin1("X-TDE-LastOpenedWith"))
112 == desktopEntryName)
113 {
114 utime(TQFile::encodeName(ddesktop), NULL);
115 return;
116 }
117 // if not append a (num) to it
118 ++i;
119 if ( i > maxEntries )
120 break;
121 ddesktop = dStr + TQString::fromLatin1("[%1].desktop").arg(i);
122 }
123
124 TQDir dir(path);
125 // check for max entries, delete oldest files if exceeded
126 TQStringList list = dir.entryList(TQDir::Files | TQDir::Hidden, TQDir::Time | TQDir::Reversed);
127 i = list.count();
128 if(i > maxEntries-1){
129 TQStringList::Iterator it;
130 it = list.begin();
131 while(i > maxEntries-1){
132 TQFile::remove(dir.absPath() + TQString::fromLatin1("/") + (*it));
133 --i, ++it;
134 }
135 }
136
137 // create the applnk
138 KSimpleConfig conf(ddesktop);
139 conf.setDesktopGroup();
140 conf.writeEntry( TQString::fromLatin1("Type"), TQString::fromLatin1("Link") );
141 conf.writePathEntry( TQString::fromLatin1("URL"), openStr );
142 // If you change the line below, change the test in the above loop
143 conf.writeEntry( TQString::fromLatin1("X-TDE-LastOpenedWith"), desktopEntryName );
144 TQString name = url.fileName();
145 if (name.isEmpty())
146 name = openStr;
147 conf.writeEntry( TQString::fromLatin1("Name"), name );
148 conf.writeEntry( TQString::fromLatin1("Icon"), KMimeType::iconForURL( url ) );
149}
150
151void TDERecentDocument::add(const TQString &openStr, bool isUrl)
152{
153 if( isUrl ) {
154 add( KURL( openStr ) );
155 } else {
156 KURL url;
157 url.setPath( openStr );
158 add( url );
159 }
160}
161
162void TDERecentDocument::clear()
163{
164 TQStringList list = recentDocuments();
165 TQDir dir;
166 for(TQStringList::Iterator it = list.begin(); it != list.end() ; ++it)
167 dir.remove(*it);
168}
169
170int TDERecentDocument::maximumItems()
171{
172 TDEConfig *config = TDEGlobal::config();
173 TDEConfigGroupSaver sa(config, TQString::fromLatin1("RecentDocuments"));
174 return config->readNumEntry(TQString::fromLatin1("MaxEntries"), 10);
175}
176
177
TDERecentDocument::recentDocuments
static TQStringList recentDocuments()
Return a list of absolute paths to recent document .desktop files, sorted by date.
Definition: tderecentdocument.cpp:51
TDERecentDocument::clear
static void clear()
Clear the recent document menu of all entries.
Definition: tderecentdocument.cpp:162
TDERecentDocument::add
static void add(const KURL &url)
Add a new item to the Recent Document menu.
Definition: tderecentdocument.cpp:75
TDERecentDocument::recentDocumentDirectory
static TQString recentDocumentDirectory()
Returns the path to the directory where recent document .desktop files are stored.
Definition: tderecentdocument.cpp:45
TDERecentDocument::maximumItems
static int maximumItems()
Returns the maximum amount of recent document entries allowed.
Definition: tderecentdocument.cpp:170

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