1
/* This file is part of the KDE project
2
Copyright (c) 2004 Kevin Ottens <ervin ipsquad net>
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; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301, USA.
24
#include <kapplication.h>
25
#include <dcopclient.h>
26
#include <kcmdlineargs.h>
28
#include <qeventloop.h>
30
#include "kio_media.h"
33
static const KCmdLineOptions options[] =
35
{ "+protocol", I18N_NOOP( "Protocol name" ), 0 },
36
{ "+pool", I18N_NOOP( "Socket name" ), 0 },
37
{ "+app", I18N_NOOP( "Socket name" ), 0 },
42
int KDE_EXPORT kdemain( int argc, char **argv )
44
// KApplication is necessary to use other ioslaves
45
putenv(strdup("SESSION_MANAGER="));
46
KCmdLineArgs::init(argc, argv, "kio_media", 0, 0, 0, 0);
47
KCmdLineArgs::addCmdLineOptions( options );
48
KApplication app( false, false );
49
// We want to be anonymous even if we use DCOP
50
app.dcopClient()->attach();
52
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
53
MediaProtocol slave( args->arg(0), args->arg(1), args->arg(2) );
60
MediaProtocol::MediaProtocol(const QCString &protocol,
61
const QCString &pool, const QCString &app)
62
: ForwardingSlaveBase(protocol, pool, app)
64
connect( &m_impl, SIGNAL( warning( const QString & ) ),
65
this, SLOT( slotWarning( const QString & ) ) );
68
MediaProtocol::~MediaProtocol()
72
bool MediaProtocol::rewriteURL(const KURL &url, KURL &newUrl)
76
if ( !m_impl.parseURL(url, name, path) )
78
error(KIO::ERR_MALFORMED_URL, url.prettyURL());
83
if ( !m_impl.realURL(name, path, newUrl) )
85
error( m_impl.lastErrorCode(), m_impl.lastErrorMessage() );
92
void MediaProtocol::put(const KURL &url, int permissions,
93
bool overwrite, bool resume)
95
kdDebug(1219) << "MediaProtocol::put: " << url << endl;
98
bool ok = m_impl.parseURL(url, name, path);
100
if ( ok && path.isEmpty() )
102
error(KIO::ERR_CANNOT_OPEN_FOR_WRITING, url.prettyURL());
106
ForwardingSlaveBase::put(url, permissions, overwrite, resume);
110
void MediaProtocol::rename(const KURL &src, const KURL &dest, bool overwrite)
112
kdDebug(1219) << "MediaProtocol::rename: " << src << ", " << dest << ", "
113
<< overwrite << endl;
115
QString src_name, src_path;
116
bool ok = m_impl.parseURL(src, src_name, src_path);
117
QString dest_name, dest_path;
118
ok &= m_impl.parseURL(dest, dest_name, dest_path);
120
if ( ok && src_path.isEmpty() && dest_path.isEmpty()
121
&& src.protocol() == "media" && dest.protocol() == "media" )
123
if (!m_impl.setUserLabel(src_name, dest_name))
125
error(m_impl.lastErrorCode(), m_impl.lastErrorMessage());
134
ForwardingSlaveBase::rename(src, dest, overwrite);
138
void MediaProtocol::mkdir(const KURL &url, int permissions)
140
kdDebug(1219) << "MediaProtocol::mkdir: " << url << endl;
143
bool ok = m_impl.parseURL(url, name, path);
145
if ( ok && path.isEmpty() )
147
error(KIO::ERR_COULD_NOT_MKDIR, url.prettyURL());
151
ForwardingSlaveBase::mkdir(url, permissions);
155
void MediaProtocol::del(const KURL &url, bool isFile)
157
kdDebug(1219) << "MediaProtocol::del: " << url << endl;
160
bool ok = m_impl.parseURL(url, name, path);
162
if ( ok && path.isEmpty() )
164
error(KIO::ERR_CANNOT_DELETE, url.prettyURL());
168
ForwardingSlaveBase::del(url, isFile);
172
void MediaProtocol::stat(const KURL &url)
174
kdDebug(1219) << "MediaProtocol::stat: " << url << endl;
175
QString path = url.path();
176
if( path.isEmpty() || path == "/" )
178
// The root is "virtual" - it's not a single physical directory
180
m_impl.createTopLevelEntry( entry );
187
bool ok = m_impl.parseURL(url, name, path);
191
error(KIO::ERR_MALFORMED_URL, url.prettyURL());
199
if ( m_impl.statMedium(name, entry)
200
|| m_impl.statMediumByLabel(name, entry) )
207
error(KIO::ERR_DOES_NOT_EXIST, url.prettyURL());
212
ForwardingSlaveBase::stat(url);
216
void MediaProtocol::listDir(const KURL &url)
218
kdDebug(1219) << "MediaProtocol::listDir: " << url << endl;
220
if ( url.path().length() <= 1 )
227
bool ok = m_impl.parseURL(url, name, path);
231
error(KIO::ERR_MALFORMED_URL, url.prettyURL());
235
ForwardingSlaveBase::listDir(url);
238
void MediaProtocol::listRoot()
242
KIO::UDSEntryList media_entries;
243
bool ok = m_impl.listMedia(media_entries);
247
error( m_impl.lastErrorCode(), m_impl.lastErrorMessage() );
251
totalSize(media_entries.count()+1);
253
m_impl.createTopLevelEntry(entry);
254
listEntry(entry, false);
256
KIO::UDSEntryListIterator it = media_entries.begin();
257
KIO::UDSEntryListIterator end = media_entries.end();
261
listEntry(*it, false);
265
listEntry(entry, true);
270
void MediaProtocol::slotWarning( const QString &msg )
275
#include "kio_media.moc"