From d888cfa39e8b38abe17f3d425d19cb8235136a79 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 1 Feb 2013 17:25:43 -0600 Subject: Fix FTBFS --- tdeio/tdefile/krecentdirs.cpp | 99 -------------------- tdeio/tdefile/krecentdirs.h | 70 -------------- tdeio/tdefile/krecentdocument.cpp | 177 ------------------------------------ tdeio/tdefile/krecentdocument.h | 105 --------------------- tdeio/tdefile/tderecentdirs.cpp | 99 ++++++++++++++++++++ tdeio/tdefile/tderecentdirs.h | 70 ++++++++++++++ tdeio/tdefile/tderecentdocument.cpp | 177 ++++++++++++++++++++++++++++++++++++ tdeio/tdefile/tderecentdocument.h | 105 +++++++++++++++++++++ 8 files changed, 451 insertions(+), 451 deletions(-) delete mode 100644 tdeio/tdefile/krecentdirs.cpp delete mode 100644 tdeio/tdefile/krecentdirs.h delete mode 100644 tdeio/tdefile/krecentdocument.cpp delete mode 100644 tdeio/tdefile/krecentdocument.h create mode 100644 tdeio/tdefile/tderecentdirs.cpp create mode 100644 tdeio/tdefile/tderecentdirs.h create mode 100644 tdeio/tdefile/tderecentdocument.cpp create mode 100644 tdeio/tdefile/tderecentdocument.h (limited to 'tdeio/tdefile') diff --git a/tdeio/tdefile/krecentdirs.cpp b/tdeio/tdefile/krecentdirs.cpp deleted file mode 100644 index 0d8d008bd..000000000 --- a/tdeio/tdefile/krecentdirs.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* -*- c++ -*- - * Copyright (C)2000 Waldo Bastian - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ -#include -#include -#include -#include - -#define MAX_DIR_HISTORY 3 - -static void recentdirs_done(TDEConfig *config) -{ - if (config == TDEGlobal::config()) - { - config->sync(); - } - else - { - delete config; - } -} - -static TDEConfig *recentdirs_readList(TQString &key, TQStringList &result, bool readOnly) -{ - TDEConfig *config; - if ((key.length() < 2) || (key[0] != ':')) - key = ":default"; - if (key[1] == ':') - { - key = key.mid(2); - config = new KSimpleConfig(TQString::fromLatin1("krecentdirsrc"), readOnly); - } - else - { - key = key.mid(1); - config = TDEGlobal::config(); - config->setGroup(TQString::fromLatin1("Recent Dirs")); - } - - result=config->readPathListEntry(key); - if (result.isEmpty()) - { - result.append(TDEGlobalSettings::documentPath()); - } - return config; -} - -TQStringList TDERecentDirs::list(const TQString &fileClass) -{ - TQString key = fileClass; - TQStringList result; - recentdirs_done(recentdirs_readList(key, result, true)); - return result; -} - -TQString TDERecentDirs::dir(const TQString &fileClass) -{ - TQStringList result = list(fileClass); - return result[0]; -} - -void TDERecentDirs::add(const TQString &fileClass, const TQString &directory) -{ - TQString key = fileClass; - TQStringList result; - TDEConfig *config = recentdirs_readList(key, result, false); - // make sure the dir is first in history - result.remove(directory); - result.prepend(directory); - while(result.count() > MAX_DIR_HISTORY) - result.remove(result.fromLast()); - config->writePathEntry(key, result); - recentdirs_done(config); -} - diff --git a/tdeio/tdefile/krecentdirs.h b/tdeio/tdefile/krecentdirs.h deleted file mode 100644 index cc9be16b4..000000000 --- a/tdeio/tdefile/krecentdirs.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- c++ -*- - * Copyright (C)2000 Waldo Bastian - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ -#ifndef __KRECENTDIRS_H -#define __KRECENTDIRS_H - -#include - -#include - -/** - * The goal of this class is to make sure that, when the user needs to - * specify a file via the file selection dialog, this dialog will start - * in the directory most likely to contain the desired files. - * - * This works as follows: Each time the file selection dialog is - * shown, the programmer can specify a "file-class". The file-dialog will - * then start with the directory associated with this file-class. When - * the dialog closes, the directory currently shown in the file-dialog - * will be associated with the file-class. - * - * A file-class can either start with ':' or with '::'. If it starts with - * a single ':' the file-class is specific to the current application. - * If the file-class starts with '::' it is global to all applications. - */ -class TDEIO_EXPORT TDERecentDirs -{ -public: - /** - * Returns a list of directories associated with this file-class. - * The most recently used directory is at the front of the list. - */ - static TQStringList list(const TQString &fileClass); - - /** - * Returns the most recently used directory accociated with this file-class. - */ - static TQString dir(const TQString &fileClass); - - /** - * Associates @p directory with @p fileClass - */ - static void add(const TQString &fileClass, const TQString &directory); -}; - -#endif diff --git a/tdeio/tdefile/krecentdocument.cpp b/tdeio/tdefile/krecentdocument.cpp deleted file mode 100644 index 85af01c46..000000000 --- a/tdeio/tdefile/krecentdocument.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* -*- c++ -*- - * Copyright (C)2000 Daniel M. Duley - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -TQString TDERecentDocument::recentDocumentDirectory() -{ - // need to change this path, not sure where - return locateLocal("data", TQString::fromLatin1("RecentDocuments/")); -} - -TQStringList TDERecentDocument::recentDocuments() -{ - TQDir d(recentDocumentDirectory(), "*.desktop", TQDir::Time, - TQDir::Files | TQDir::Readable | TQDir::Hidden); - - if (!d.exists()) - d.mkdir(recentDocumentDirectory()); - - TQStringList list = d.entryList(); - TQStringList fullList; - - for (TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it) { - TQString pathDesktop = d.absFilePath( *it ); - KDesktopFile tmpDesktopFile( pathDesktop, false); - KURL urlDesktopFile(tmpDesktopFile.readURL()); - if( urlDesktopFile.isLocalFile() && !TQFile(urlDesktopFile.path()).exists()) - d.remove(pathDesktop); - else - fullList.append( pathDesktop ); - } - - return fullList; -} - -void TDERecentDocument::add(const KURL& url) -{ - TDERecentDocument::add(url, tqApp->argv()[0]); // ### argv[0] might not match the service filename! -} - -void TDERecentDocument::add(const KURL& url, const TQString& desktopEntryName) -{ - if ( url.isLocalFile() && !TDEGlobal::dirs()->relativeLocation("tmp", url.path()).startsWith("/")) - return; - - TQString openStr = url.url(); - openStr.replace( TQRegExp("\\$"), "$$" ); // Desktop files with type "Link" are $-variable expanded - - kdDebug(250) << "TDERecentDocument::add for " << openStr << endl; - TDEConfig *config = TDEGlobal::config(); - TQString oldGrp = config->group(); - config->setGroup(TQString::fromLatin1("RecentDocuments")); - bool useRecent = config->readBoolEntry(TQString::fromLatin1("UseRecent"), true); - int maxEntries = config->readNumEntry(TQString::fromLatin1("MaxEntries"), 10); - - config->setGroup(oldGrp); - if(!useRecent) - return; - - TQString path = recentDocumentDirectory(); - - TQString dStr = path + url.fileName(); - - TQString ddesktop = dStr + TQString::fromLatin1(".desktop"); - - int i=1; - // check for duplicates - while(TQFile::exists(ddesktop)){ - // see if it points to the same file and application - KSimpleConfig tmp(ddesktop); - tmp.setDesktopGroup(); - if(tmp.readEntry(TQString::fromLatin1("X-TDE-LastOpenedWith")) - == desktopEntryName) - { - utime(TQFile::encodeName(ddesktop), NULL); - return; - } - // if not append a (num) to it - ++i; - if ( i > maxEntries ) - break; - ddesktop = dStr + TQString::fromLatin1("[%1].desktop").arg(i); - } - - TQDir dir(path); - // check for max entries, delete oldest files if exceeded - TQStringList list = dir.entryList(TQDir::Files | TQDir::Hidden, TQDir::Time | TQDir::Reversed); - i = list.count(); - if(i > maxEntries-1){ - TQStringList::Iterator it; - it = list.begin(); - while(i > maxEntries-1){ - TQFile::remove(dir.absPath() + TQString::fromLatin1("/") + (*it)); - --i, ++it; - } - } - - // create the applnk - KSimpleConfig conf(ddesktop); - conf.setDesktopGroup(); - conf.writeEntry( TQString::fromLatin1("Type"), TQString::fromLatin1("Link") ); - conf.writePathEntry( TQString::fromLatin1("URL"), openStr ); - // If you change the line below, change the test in the above loop - conf.writeEntry( TQString::fromLatin1("X-TDE-LastOpenedWith"), desktopEntryName ); - TQString name = url.fileName(); - if (name.isEmpty()) - name = openStr; - conf.writeEntry( TQString::fromLatin1("Name"), name ); - conf.writeEntry( TQString::fromLatin1("Icon"), KMimeType::iconForURL( url ) ); -} - -void TDERecentDocument::add(const TQString &openStr, bool isUrl) -{ - if( isUrl ) { - add( KURL( openStr ) ); - } else { - KURL url; - url.setPath( openStr ); - add( url ); - } -} - -void TDERecentDocument::clear() -{ - TQStringList list = recentDocuments(); - TQDir dir; - for(TQStringList::Iterator it = list.begin(); it != list.end() ; ++it) - dir.remove(*it); -} - -int TDERecentDocument::maximumItems() -{ - TDEConfig *config = TDEGlobal::config(); - TDEConfigGroupSaver sa(config, TQString::fromLatin1("RecentDocuments")); - return config->readNumEntry(TQString::fromLatin1("MaxEntries"), 10); -} - - diff --git a/tdeio/tdefile/krecentdocument.h b/tdeio/tdefile/krecentdocument.h deleted file mode 100644 index b788c0dc2..000000000 --- a/tdeio/tdefile/krecentdocument.h +++ /dev/null @@ -1,105 +0,0 @@ -/* -*- c++ -*- - * Copyright (C)2000 Daniel M. Duley - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ -#ifndef __KRECENTDOCUMENT_H -#define __KRECENTDOCUMENT_H - -#include -#include - -/** - * Manage the "Recent Document Menu" entries displayed by - * applications such as Kicker and Konqueror. - * - * These entries are automatically generated .desktop files pointing - * to the current application and document. You should call the - * static add() method whenever the user opens or saves a new - * document if you want it to show up in the menu. - * - * You don't have to worry about this if you are using any - * KFileDialog derived class to open and save documents, as it - * already calls this class. User defined limits on the maximum - * number of documents to save, etc... are all automatically handled. - * - * @author Daniel M. Duley - */ -class TDEIO_EXPORT TDERecentDocument -{ -public: - - /** - * - * Return a list of absolute paths to recent document .desktop files, - * sorted by date. - * - */ - static TQStringList recentDocuments(); - - /** - * Add a new item to the Recent Document menu. - * - * @param url The url to add. - */ - static void add(const KURL& url); - - /** - * Add a new item to the Recent Document menu, specifying the application to open it with. - * The above add() method uses argv[0] for the app name, which isn't always flexible enough. - * This method is used when an application launches another one to open a document. - * - * @param url The url to add. - * @param desktopEntryName The desktopEntryName of the service to use for opening this document. - */ - static void add(const KURL& url, const TQString& desktopEntryName); - - /** - * - * Add a new item to the Recent Document menu. Calls add( url ). - * - * @param documentStr The full path to the document or URL to add. - * @param isURL Set to @p true if @p documentStr is an URL and not a local file path. - */ - static void add(const TQString &documentStr, bool isURL = false); - - /** - * Clear the recent document menu of all entries. - */ - static void clear(); - - /** - * Returns the maximum amount of recent document entries allowed. - */ - static int maximumItems(); - - /** - * Returns the path to the directory where recent document .desktop files - * are stored. - */ - static TQString recentDocumentDirectory(); -}; - -#endif diff --git a/tdeio/tdefile/tderecentdirs.cpp b/tdeio/tdefile/tderecentdirs.cpp new file mode 100644 index 000000000..0d8d008bd --- /dev/null +++ b/tdeio/tdefile/tderecentdirs.cpp @@ -0,0 +1,99 @@ +/* -*- c++ -*- + * Copyright (C)2000 Waldo Bastian + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ +#include +#include +#include +#include + +#define MAX_DIR_HISTORY 3 + +static void recentdirs_done(TDEConfig *config) +{ + if (config == TDEGlobal::config()) + { + config->sync(); + } + else + { + delete config; + } +} + +static TDEConfig *recentdirs_readList(TQString &key, TQStringList &result, bool readOnly) +{ + TDEConfig *config; + if ((key.length() < 2) || (key[0] != ':')) + key = ":default"; + if (key[1] == ':') + { + key = key.mid(2); + config = new KSimpleConfig(TQString::fromLatin1("krecentdirsrc"), readOnly); + } + else + { + key = key.mid(1); + config = TDEGlobal::config(); + config->setGroup(TQString::fromLatin1("Recent Dirs")); + } + + result=config->readPathListEntry(key); + if (result.isEmpty()) + { + result.append(TDEGlobalSettings::documentPath()); + } + return config; +} + +TQStringList TDERecentDirs::list(const TQString &fileClass) +{ + TQString key = fileClass; + TQStringList result; + recentdirs_done(recentdirs_readList(key, result, true)); + return result; +} + +TQString TDERecentDirs::dir(const TQString &fileClass) +{ + TQStringList result = list(fileClass); + return result[0]; +} + +void TDERecentDirs::add(const TQString &fileClass, const TQString &directory) +{ + TQString key = fileClass; + TQStringList result; + TDEConfig *config = recentdirs_readList(key, result, false); + // make sure the dir is first in history + result.remove(directory); + result.prepend(directory); + while(result.count() > MAX_DIR_HISTORY) + result.remove(result.fromLast()); + config->writePathEntry(key, result); + recentdirs_done(config); +} + diff --git a/tdeio/tdefile/tderecentdirs.h b/tdeio/tdefile/tderecentdirs.h new file mode 100644 index 000000000..cc9be16b4 --- /dev/null +++ b/tdeio/tdefile/tderecentdirs.h @@ -0,0 +1,70 @@ +/* -*- c++ -*- + * Copyright (C)2000 Waldo Bastian + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ +#ifndef __KRECENTDIRS_H +#define __KRECENTDIRS_H + +#include + +#include + +/** + * The goal of this class is to make sure that, when the user needs to + * specify a file via the file selection dialog, this dialog will start + * in the directory most likely to contain the desired files. + * + * This works as follows: Each time the file selection dialog is + * shown, the programmer can specify a "file-class". The file-dialog will + * then start with the directory associated with this file-class. When + * the dialog closes, the directory currently shown in the file-dialog + * will be associated with the file-class. + * + * A file-class can either start with ':' or with '::'. If it starts with + * a single ':' the file-class is specific to the current application. + * If the file-class starts with '::' it is global to all applications. + */ +class TDEIO_EXPORT TDERecentDirs +{ +public: + /** + * Returns a list of directories associated with this file-class. + * The most recently used directory is at the front of the list. + */ + static TQStringList list(const TQString &fileClass); + + /** + * Returns the most recently used directory accociated with this file-class. + */ + static TQString dir(const TQString &fileClass); + + /** + * Associates @p directory with @p fileClass + */ + static void add(const TQString &fileClass, const TQString &directory); +}; + +#endif diff --git a/tdeio/tdefile/tderecentdocument.cpp b/tdeio/tdefile/tderecentdocument.cpp new file mode 100644 index 000000000..85af01c46 --- /dev/null +++ b/tdeio/tdefile/tderecentdocument.cpp @@ -0,0 +1,177 @@ +/* -*- c++ -*- + * Copyright (C)2000 Daniel M. Duley + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +TQString TDERecentDocument::recentDocumentDirectory() +{ + // need to change this path, not sure where + return locateLocal("data", TQString::fromLatin1("RecentDocuments/")); +} + +TQStringList TDERecentDocument::recentDocuments() +{ + TQDir d(recentDocumentDirectory(), "*.desktop", TQDir::Time, + TQDir::Files | TQDir::Readable | TQDir::Hidden); + + if (!d.exists()) + d.mkdir(recentDocumentDirectory()); + + TQStringList list = d.entryList(); + TQStringList fullList; + + for (TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it) { + TQString pathDesktop = d.absFilePath( *it ); + KDesktopFile tmpDesktopFile( pathDesktop, false); + KURL urlDesktopFile(tmpDesktopFile.readURL()); + if( urlDesktopFile.isLocalFile() && !TQFile(urlDesktopFile.path()).exists()) + d.remove(pathDesktop); + else + fullList.append( pathDesktop ); + } + + return fullList; +} + +void TDERecentDocument::add(const KURL& url) +{ + TDERecentDocument::add(url, tqApp->argv()[0]); // ### argv[0] might not match the service filename! +} + +void TDERecentDocument::add(const KURL& url, const TQString& desktopEntryName) +{ + if ( url.isLocalFile() && !TDEGlobal::dirs()->relativeLocation("tmp", url.path()).startsWith("/")) + return; + + TQString openStr = url.url(); + openStr.replace( TQRegExp("\\$"), "$$" ); // Desktop files with type "Link" are $-variable expanded + + kdDebug(250) << "TDERecentDocument::add for " << openStr << endl; + TDEConfig *config = TDEGlobal::config(); + TQString oldGrp = config->group(); + config->setGroup(TQString::fromLatin1("RecentDocuments")); + bool useRecent = config->readBoolEntry(TQString::fromLatin1("UseRecent"), true); + int maxEntries = config->readNumEntry(TQString::fromLatin1("MaxEntries"), 10); + + config->setGroup(oldGrp); + if(!useRecent) + return; + + TQString path = recentDocumentDirectory(); + + TQString dStr = path + url.fileName(); + + TQString ddesktop = dStr + TQString::fromLatin1(".desktop"); + + int i=1; + // check for duplicates + while(TQFile::exists(ddesktop)){ + // see if it points to the same file and application + KSimpleConfig tmp(ddesktop); + tmp.setDesktopGroup(); + if(tmp.readEntry(TQString::fromLatin1("X-TDE-LastOpenedWith")) + == desktopEntryName) + { + utime(TQFile::encodeName(ddesktop), NULL); + return; + } + // if not append a (num) to it + ++i; + if ( i > maxEntries ) + break; + ddesktop = dStr + TQString::fromLatin1("[%1].desktop").arg(i); + } + + TQDir dir(path); + // check for max entries, delete oldest files if exceeded + TQStringList list = dir.entryList(TQDir::Files | TQDir::Hidden, TQDir::Time | TQDir::Reversed); + i = list.count(); + if(i > maxEntries-1){ + TQStringList::Iterator it; + it = list.begin(); + while(i > maxEntries-1){ + TQFile::remove(dir.absPath() + TQString::fromLatin1("/") + (*it)); + --i, ++it; + } + } + + // create the applnk + KSimpleConfig conf(ddesktop); + conf.setDesktopGroup(); + conf.writeEntry( TQString::fromLatin1("Type"), TQString::fromLatin1("Link") ); + conf.writePathEntry( TQString::fromLatin1("URL"), openStr ); + // If you change the line below, change the test in the above loop + conf.writeEntry( TQString::fromLatin1("X-TDE-LastOpenedWith"), desktopEntryName ); + TQString name = url.fileName(); + if (name.isEmpty()) + name = openStr; + conf.writeEntry( TQString::fromLatin1("Name"), name ); + conf.writeEntry( TQString::fromLatin1("Icon"), KMimeType::iconForURL( url ) ); +} + +void TDERecentDocument::add(const TQString &openStr, bool isUrl) +{ + if( isUrl ) { + add( KURL( openStr ) ); + } else { + KURL url; + url.setPath( openStr ); + add( url ); + } +} + +void TDERecentDocument::clear() +{ + TQStringList list = recentDocuments(); + TQDir dir; + for(TQStringList::Iterator it = list.begin(); it != list.end() ; ++it) + dir.remove(*it); +} + +int TDERecentDocument::maximumItems() +{ + TDEConfig *config = TDEGlobal::config(); + TDEConfigGroupSaver sa(config, TQString::fromLatin1("RecentDocuments")); + return config->readNumEntry(TQString::fromLatin1("MaxEntries"), 10); +} + + diff --git a/tdeio/tdefile/tderecentdocument.h b/tdeio/tdefile/tderecentdocument.h new file mode 100644 index 000000000..b788c0dc2 --- /dev/null +++ b/tdeio/tdefile/tderecentdocument.h @@ -0,0 +1,105 @@ +/* -*- c++ -*- + * Copyright (C)2000 Daniel M. Duley + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ +#ifndef __KRECENTDOCUMENT_H +#define __KRECENTDOCUMENT_H + +#include +#include + +/** + * Manage the "Recent Document Menu" entries displayed by + * applications such as Kicker and Konqueror. + * + * These entries are automatically generated .desktop files pointing + * to the current application and document. You should call the + * static add() method whenever the user opens or saves a new + * document if you want it to show up in the menu. + * + * You don't have to worry about this if you are using any + * KFileDialog derived class to open and save documents, as it + * already calls this class. User defined limits on the maximum + * number of documents to save, etc... are all automatically handled. + * + * @author Daniel M. Duley + */ +class TDEIO_EXPORT TDERecentDocument +{ +public: + + /** + * + * Return a list of absolute paths to recent document .desktop files, + * sorted by date. + * + */ + static TQStringList recentDocuments(); + + /** + * Add a new item to the Recent Document menu. + * + * @param url The url to add. + */ + static void add(const KURL& url); + + /** + * Add a new item to the Recent Document menu, specifying the application to open it with. + * The above add() method uses argv[0] for the app name, which isn't always flexible enough. + * This method is used when an application launches another one to open a document. + * + * @param url The url to add. + * @param desktopEntryName The desktopEntryName of the service to use for opening this document. + */ + static void add(const KURL& url, const TQString& desktopEntryName); + + /** + * + * Add a new item to the Recent Document menu. Calls add( url ). + * + * @param documentStr The full path to the document or URL to add. + * @param isURL Set to @p true if @p documentStr is an URL and not a local file path. + */ + static void add(const TQString &documentStr, bool isURL = false); + + /** + * Clear the recent document menu of all entries. + */ + static void clear(); + + /** + * Returns the maximum amount of recent document entries allowed. + */ + static int maximumItems(); + + /** + * Returns the path to the directory where recent document .desktop files + * are stored. + */ + static TQString recentDocumentDirectory(); +}; + +#endif -- cgit v1.2.1