• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KIOSlave

  • kioslave
  • metainfo
metainfo.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 2002 Rolf Magnus <ramagnus@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation version 2.0
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*/
18
19#include "metainfo.h"
20
21#include <kurl.h>
22#include <kaboutdata.h>
23#include <kcmdlineargs.h>
24#include <kapplication.h>
25#include <kmimetype.h>
26#include <kdebug.h>
27#include <kfilemetainfo.h>
28#include <klocale.h>
29#include <stdlib.h>
30
31// Recognized metadata entries:
32// mimeType - the mime type of the file, so we need not extra determine it
33// what - what to load
34
35using namespace KIO;
36
37extern "C" int KDE_EXPORT kdemain(int argc, char **argv)
38{
39 KAboutData about("kio_metainfo", 0, ki18n("kio_metainfo"), 0);
40 KCmdLineArgs::init(&about);
41
42 KApplication app;
43
44 //KApplication app(argc, argv, "kio_metainfo", false, true);
45
46 if (argc != 4)
47 {
48 kError() << "Usage: kio_metainfo protocol domain-socket1 domain-socket2" << endl;
49 exit(-1);
50 }
51
52 MetaInfoProtocol slave(argv[2], argv[3]);
53 slave.dispatchLoop();
54
55 return 0;
56}
57
58MetaInfoProtocol::MetaInfoProtocol(const QByteArray &pool, const QByteArray &app)
59 : SlaveBase("metainfo", pool, app)
60{
61}
62
63MetaInfoProtocol::~MetaInfoProtocol()
64{
65}
66
67void MetaInfoProtocol::get(const KUrl &url)
68{
69 QString mimeType = metaData("mimeType");
70 KFileMetaInfo info(url.toLocalFile(), mimeType);
71
72 QByteArray arr;
73 QDataStream stream(&arr, QIODevice::WriteOnly);
74
75 stream << info;
76
77 data(arr);
78 finished();
79}
80
81void MetaInfoProtocol::put(const KUrl& url, int, KIO::JobFlags)
82{
83 QString mimeType = metaData("mimeType");
84 KFileMetaInfo info;
85
86 QByteArray arr;
87 readData(arr);
88 QDataStream stream(arr);
89
90 stream >> info;
91
92 if (info.isValid())
93 {
94 info.applyChanges();
95 }
96 else
97 {
98 error(ERR_NO_CONTENT, i18n("No metainfo for %1", url.path()));
99 return;
100 }
101 finished();
102}
KAboutData
KApplication
KCmdLineArgs::init
static void init(const KAboutData *about)
KFileMetaInfo
KFileMetaInfo::isValid
bool isValid() const
KFileMetaInfo::applyChanges
bool applyChanges()
KIO::SlaveBase
KIO::SlaveBase::mimeType
void mimeType(const QString &_type)
KIO::SlaveBase::metaData
QString metaData(const QString &key) const
KIO::SlaveBase::finished
void finished()
KIO::SlaveBase::error
void error(int _errid, const QString &_text)
KIO::SlaveBase::dispatchLoop
void dispatchLoop()
KIO::SlaveBase::readData
int readData(QByteArray &buffer)
KIO::SlaveBase::data
void data(const QByteArray &data)
KUrl
KUrl::path
QString path(AdjustPathOption trailing=LeaveTrailingSlash) const
KUrl::toLocalFile
QString toLocalFile(AdjustPathOption trailing=LeaveTrailingSlash) const
MetaInfoProtocol
Definition: metainfo.h:25
MetaInfoProtocol::put
virtual void put(const KUrl &url, int permissions, KIO::JobFlags flags)
Definition: metainfo.cpp:81
MetaInfoProtocol::~MetaInfoProtocol
virtual ~MetaInfoProtocol()
Definition: metainfo.cpp:63
MetaInfoProtocol::get
virtual void get(const KUrl &url)
Definition: metainfo.cpp:67
MetaInfoProtocol::MetaInfoProtocol
MetaInfoProtocol(const QByteArray &pool, const QByteArray &app)
Definition: metainfo.cpp:58
kaboutdata.h
kapplication.h
kcmdlineargs.h
kdebug.h
kfilemetainfo.h
klocale.h
ki18n
KLocalizedString ki18n(const char *msg)
i18n
QString i18n(const char *text)
kmimetype.h
kurl.h
kdemain
int kdemain(int argc, char **argv)
Definition: metainfo.cpp:37
metainfo.h
KIO
ERR_NO_CONTENT
ERR_NO_CONTENT
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIOSlave

Skip menu "KIOSlave"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal