diff options
| author | Michele Calgaro <michele.calgaro@yahoo.it> | 2025-02-10 15:10:13 +0900 | 
|---|---|---|
| committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2025-02-10 15:10:13 +0900 | 
| commit | 203fcb8d90752b546c672c625927a136b959fcfb (patch) | |
| tree | a899621e4cb63e2cdd9b94f889ee9d0ae8561bf0 /src/sq_archivehandler.cpp | |
| parent | 98c274834c63c7fa4a9a494fdf7cd483336714d5 (diff) | |
| download | ksquirrel-203fcb8d90752b546c672c625927a136b959fcfb.tar.gz ksquirrel-203fcb8d90752b546c672c625927a136b959fcfb.zip | |
Rename 'ksquirrel' folder to 'src'
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'src/sq_archivehandler.cpp')
| -rw-r--r-- | src/sq_archivehandler.cpp | 114 | 
1 files changed, 114 insertions, 0 deletions
| diff --git a/src/sq_archivehandler.cpp b/src/sq_archivehandler.cpp new file mode 100644 index 0000000..9c4ce55 --- /dev/null +++ b/src/sq_archivehandler.cpp @@ -0,0 +1,114 @@ +/*************************************************************************** +                          sq_archivehandler.cpp  -  description +                             ------------------- +    begin                : ??? ??? 26 2004 +    copyright            : (C) 2004 by Baryshev Dmitry +    email                : ksquirrel.iv@gmail.com + ***************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <tdemessagebox.h> +#include <tdeglobal.h> +#include <kstandarddirs.h> +#include <tdefileitem.h> +#include <tdelocale.h> +#include <kurl.h> + +#include "sq_archivehandler.h" + +SQ_ArchiveHandler * SQ_ArchiveHandler::m_instance = 0; + +SQ_ArchiveHandler::SQ_ArchiveHandler(TQObject * parent, const char *name) +    : TQObject(parent, name), TQMap<TQString, TQString>() +{ +    m_instance = this; + +    fillProtocols(); +} + +SQ_ArchiveHandler::~SQ_ArchiveHandler() +{} + +void SQ_ArchiveHandler::fillProtocols() +{ +    // search for tar protocol +    if(!TDEGlobal::dirs()->findResource("services", "tar.protocol").isEmpty()) +    { +        insert("application/x-tgz",  "tar"); +        insert("application/x-tar",  "tar"); +        insert("application/x-tarz", "tar"); +        insert("application/x-tbz",  "tar"); +        insert("application/x-tzo",  "tar"); +    } + +    // search for rar protocol (tdeio_rar from +    // http://kde-apps.org/content/show.php/tdeio_rar?content=17527) +    if(!TDEGlobal::dirs()->findResource("services", "rar.protocol").isEmpty()) +    { +        insert("application/x-rar", "rar"); +    } + +    // search for ar protocol +    if(!TDEGlobal::dirs()->findResource("services", "ar.protocol").isEmpty()) +        insert("application/x-archive", "ar"); + +    // search for iso protocol +    if(!TDEGlobal::dirs()->findResource("services", "iso.protocol").isEmpty()) +        insert("application/x-iso", "iso"); + +    // search for zip protocol +    if(!TDEGlobal::dirs()->findResource("services", "zip.protocol").isEmpty()) +        insert("application/x-zip", "zip"); + +    // search for 7zip protocol (tdeio_p7zip +    // from http://kde-apps.org/content/show.php/tdeio_p7zip?content=17829) +    if(!TDEGlobal::dirs()->findResource("services", "p7zip.protocol").isEmpty()) +        insert("application/x-7z", "p7zip"); +} + +/* + *  Find protocol name by mimetype name. + *  + *  For example findProtocolByMime(""application/x-tgz"") will + *  return "tar". + */ +TQString SQ_ArchiveHandler::findProtocolByMime(const TQString &mime) +{ +    // find protocol +    TQMap<TQString, TQString>::iterator it = find(mime); + +    // return protocol number, if found, and -1 otherwise +    return (it == end() ? TQString() : it.data()); +} + +/* + *  Find protocol name by KFileItem's mimetype. + */ +TQString SQ_ArchiveHandler::findProtocolByFile(KFileItem *item) +{ +    return item ? findProtocolByMime(item->mimetype()) : TQString(); +} + +void SQ_ArchiveHandler::tryUnpack(KFileItem *item) +{ +    if(item) tryUnpack(item->url(), item->mimetype()); +} + +void SQ_ArchiveHandler::tryUnpack(const KURL &url, const TQString &mime) +{ +    TQString prot = findProtocolByMime(mime); + +    if(!prot.isEmpty()) +    { +        // just change protocol, TDEIO::get() will do all for us +        KURL _url = url; +        _url.setProtocol(prot); + +        emit unpack(_url); +    } +} + +#include "sq_archivehandler.moc" | 
