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

KIOSlave

  • sources
  • kde-4.12
  • kdelibs
  • 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 
35 using namespace KIO;
36 
37 extern "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 
58 MetaInfoProtocol::MetaInfoProtocol(const QByteArray &pool, const QByteArray &app)
59  : SlaveBase("metainfo", pool, app)
60 {
61 }
62 
63 MetaInfoProtocol::~MetaInfoProtocol()
64 {
65 }
66 
67 void 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 
81 void 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 }
MetaInfoProtocol::MetaInfoProtocol
MetaInfoProtocol(const QByteArray &pool, const QByteArray &app)
Definition: metainfo.cpp:58
i18n
QString i18n(const char *text)
KApplication
metainfo.h
MetaInfoProtocol::put
virtual void put(const KUrl &url, int permissions, KIO::JobFlags flags)
Definition: metainfo.cpp:81
kdebug.h
kmimetype.h
kapplication.h
kurl.h
ki18n
KLocalizedString ki18n(const char *msg)
kError
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KUrl::toLocalFile
QString toLocalFile(AdjustPathOption trailing=LeaveTrailingSlash) const
QString
MetaInfoProtocol::get
virtual void get(const KUrl &url)
Definition: metainfo.cpp:67
klocale.h
KUrl
KFileMetaInfo
KFileMetaInfo::applyChanges
bool applyChanges()
KIO::SlaveBase
kcmdlineargs.h
MetaInfoProtocol
Definition: metainfo.h:24
KAboutData
KUrl::path
QString path(AdjustPathOption trailing=LeaveTrailingSlash) const
kdemain
int kdemain(int argc, char **argv)
Definition: metainfo.cpp:37
kfilemetainfo.h
KCmdLineArgs::init
static void init(int argc, char **argv, const QByteArray &appname, const QByteArray &catalog, const KLocalizedString &programName, const QByteArray &version, const KLocalizedString &description=KLocalizedString(), StdCmdLineArgs stdargs=StdCmdLineArgs(CmdLineArgQt|CmdLineArgKDE))
ERR_NO_CONTENT
kaboutdata.h
MetaInfoProtocol::~MetaInfoProtocol
virtual ~MetaInfoProtocol()
Definition: metainfo.cpp:63
KDE_EXPORT
#define KDE_EXPORT
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:50:58 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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