28 #include <tderecentdocument.h>
29 #include <ksimpleconfig.h>
30 #include <kstandarddirs.h>
31 #include <tdeapplication.h>
34 #include <kmimetype.h>
35 #include <kdesktopfile.h>
37 #include <tqfileinfo.h>
38 #include <tqtextstream.h>
39 #include <tqstringlist.h>
42 #include <sys/types.h>
48 return locateLocal(
"data", TQString::fromLatin1(
"RecentDocuments/"));
54 TQDir::Files | TQDir::Readable | TQDir::Hidden);
59 TQStringList list = d.entryList();
60 TQStringList fullList;
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);
69 fullList.append( pathDesktop );
82 if ( url.isLocalFile() && !TDEGlobal::dirs()->relativeLocation(
"tmp", url.path()).startsWith(
"/"))
85 TQString openStr = url.url();
86 openStr.replace( TQRegExp(
"\\$"),
"$$" );
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);
95 config->setGroup(oldGrp);
101 TQString dStr = path + url.fileName();
103 TQString ddesktop = dStr + TQString::fromLatin1(
".desktop");
107 while(TQFile::exists(ddesktop)){
109 KSimpleConfig tmp(ddesktop);
110 tmp.setDesktopGroup();
111 if(tmp.readEntry(TQString::fromLatin1(
"X-TDE-LastOpenedWith"))
114 utime(TQFile::encodeName(ddesktop), NULL);
119 if ( i > maxEntries )
121 ddesktop = dStr + TQString::fromLatin1(
"[%1].desktop").arg(i);
126 TQStringList list = dir.entryList(TQDir::Files | TQDir::Hidden, TQDir::Time | TQDir::Reversed);
128 if(i > maxEntries-1){
129 TQStringList::Iterator it;
131 while(i > maxEntries-1){
132 TQFile::remove(dir.absPath() + TQString::fromLatin1(
"/") + (*it));
138 KSimpleConfig conf(ddesktop);
139 conf.setDesktopGroup();
140 conf.writeEntry( TQString::fromLatin1(
"Type"), TQString::fromLatin1(
"Link") );
141 conf.writePathEntry( TQString::fromLatin1(
"URL"), openStr );
143 conf.writeEntry( TQString::fromLatin1(
"X-TDE-LastOpenedWith"), desktopEntryName );
144 TQString name = url.fileName();
147 conf.writeEntry( TQString::fromLatin1(
"Name"), name );
148 conf.writeEntry( TQString::fromLatin1(
"Icon"), KMimeType::iconForURL( url ) );
154 add( KURL( openStr ) );
157 url.setPath( openStr );
166 for(TQStringList::Iterator it = list.begin(); it != list.end() ; ++it)
172 TDEConfig *config = TDEGlobal::config();
173 TDEConfigGroupSaver sa(config, TQString::fromLatin1(
"RecentDocuments"));
174 return config->readNumEntry(TQString::fromLatin1(
"MaxEntries"), 10);
static TQStringList recentDocuments()
Return a list of absolute paths to recent document .desktop files, sorted by date.
static void clear()
Clear the recent document menu of all entries.
static void add(const KURL &url)
Add a new item to the Recent Document menu.
static TQString recentDocumentDirectory()
Returns the path to the directory where recent document .desktop files are stored.
static int maximumItems()
Returns the maximum amount of recent document entries allowed.