KIOSlave
metainfo.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2002 Rolf Magnus <ramagnus@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation version 2.0 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 00017 */ 00018 00019 #include "metainfo.h" 00020 00021 #include <kurl.h> 00022 #include <kaboutdata.h> 00023 #include <kcmdlineargs.h> 00024 #include <kapplication.h> 00025 #include <kmimetype.h> 00026 #include <kdebug.h> 00027 #include <kfilemetainfo.h> 00028 #include <klocale.h> 00029 #include <stdlib.h> 00030 00031 // Recognized metadata entries: 00032 // mimeType - the mime type of the file, so we need not extra determine it 00033 // what - what to load 00034 00035 using namespace KIO; 00036 00037 extern "C" int KDE_EXPORT kdemain(int argc, char **argv) 00038 { 00039 KAboutData about("kio_metainfo", 0, ki18n("kio_metainfo"), 0); 00040 KCmdLineArgs::init(&about); 00041 00042 KApplication app; 00043 00044 //KApplication app(argc, argv, "kio_metainfo", false, true); 00045 00046 if (argc != 4) 00047 { 00048 kError() << "Usage: kio_metainfo protocol domain-socket1 domain-socket2" << endl; 00049 exit(-1); 00050 } 00051 00052 MetaInfoProtocol slave(argv[2], argv[3]); 00053 slave.dispatchLoop(); 00054 00055 return 0; 00056 } 00057 00058 MetaInfoProtocol::MetaInfoProtocol(const QByteArray &pool, const QByteArray &app) 00059 : SlaveBase("metainfo", pool, app) 00060 { 00061 } 00062 00063 MetaInfoProtocol::~MetaInfoProtocol() 00064 { 00065 } 00066 00067 void MetaInfoProtocol::get(const KUrl &url) 00068 { 00069 QString mimeType = metaData("mimeType"); 00070 KFileMetaInfo info(url.toLocalFile(), mimeType); 00071 00072 QByteArray arr; 00073 QDataStream stream(&arr, QIODevice::WriteOnly); 00074 00075 stream << info; 00076 00077 data(arr); 00078 finished(); 00079 } 00080 00081 void MetaInfoProtocol::put(const KUrl& url, int, KIO::JobFlags) 00082 { 00083 QString mimeType = metaData("mimeType"); 00084 KFileMetaInfo info; 00085 00086 QByteArray arr; 00087 readData(arr); 00088 QDataStream stream(arr); 00089 00090 stream >> info; 00091 00092 if (info.isValid()) 00093 { 00094 info.applyChanges(); 00095 } 00096 else 00097 { 00098 error(ERR_NO_CONTENT, i18n("No metainfo for %1", url.path())); 00099 return; 00100 } 00101 finished(); 00102 }
KDE 4.6 API Reference