You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
277 lines
6.0 KiB
277 lines
6.0 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (c) 2004 Kevin Ottens <ervin ipsquad net>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
#include <kdebug.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kapplication.h>
|
||
|
#include <dcopclient.h>
|
||
|
#include <kcmdlineargs.h>
|
||
|
|
||
15 years ago
|
#include <tqeventloop.h>
|
||
15 years ago
|
|
||
14 years ago
|
#include "mediaimpl.h"
|
||
12 years ago
|
#include "tdeio_media.h"
|
||
15 years ago
|
|
||
|
|
||
|
static const KCmdLineOptions options[] =
|
||
|
{
|
||
|
{ "+protocol", I18N_NOOP( "Protocol name" ), 0 },
|
||
|
{ "+pool", I18N_NOOP( "Socket name" ), 0 },
|
||
|
{ "+app", I18N_NOOP( "Socket name" ), 0 },
|
||
|
KCmdLineLastOption
|
||
|
};
|
||
|
|
||
|
extern "C" {
|
||
|
int KDE_EXPORT kdemain( int argc, char **argv )
|
||
|
{
|
||
12 years ago
|
// TDEApplication is necessary to use other ioslaves
|
||
15 years ago
|
putenv(strdup("SESSION_MANAGER="));
|
||
12 years ago
|
TDECmdLineArgs::init(argc, argv, "tdeio_media", 0, 0, 0, 0);
|
||
12 years ago
|
TDECmdLineArgs::addCmdLineOptions( options );
|
||
12 years ago
|
TDEApplication app( false, false );
|
||
15 years ago
|
// We want to be anonymous even if we use DCOP
|
||
|
app.dcopClient()->attach();
|
||
|
|
||
12 years ago
|
TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
|
||
15 years ago
|
MediaProtocol slave( args->arg(0), args->arg(1), args->arg(2) );
|
||
|
slave.dispatchLoop();
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
MediaProtocol::MediaProtocol(const TQCString &protocol,
|
||
|
const TQCString &pool, const TQCString &app)
|
||
15 years ago
|
: ForwardingSlaveBase(protocol, pool, app)
|
||
|
{
|
||
15 years ago
|
connect( &m_impl, TQT_SIGNAL( warning( const TQString & ) ),
|
||
|
this, TQT_SLOT( slotWarning( const TQString & ) ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
MediaProtocol::~MediaProtocol()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
bool MediaProtocol::rewriteURL(const KURL &url, KURL &newUrl)
|
||
|
{
|
||
15 years ago
|
TQString name, path;
|
||
15 years ago
|
|
||
|
if ( !m_impl.parseURL(url, name, path) )
|
||
|
{
|
||
12 years ago
|
error(TDEIO::ERR_MALFORMED_URL, url.prettyURL());
|
||
15 years ago
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
|
if ( !m_impl.realURL(name, path, newUrl) )
|
||
|
{
|
||
|
error( m_impl.lastErrorCode(), m_impl.lastErrorMessage() );
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void MediaProtocol::put(const KURL &url, int permissions,
|
||
|
bool overwrite, bool resume)
|
||
|
{
|
||
|
kdDebug(1219) << "MediaProtocol::put: " << url << endl;
|
||
|
|
||
15 years ago
|
TQString name, path;
|
||
15 years ago
|
bool ok = m_impl.parseURL(url, name, path);
|
||
|
|
||
|
if ( ok && path.isEmpty() )
|
||
|
{
|
||
12 years ago
|
error(TDEIO::ERR_CANNOT_OPEN_FOR_WRITING, url.prettyURL());
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
ForwardingSlaveBase::put(url, permissions, overwrite, resume);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void MediaProtocol::rename(const KURL &src, const KURL &dest, bool overwrite)
|
||
|
{
|
||
|
kdDebug(1219) << "MediaProtocol::rename: " << src << ", " << dest << ", "
|
||
|
<< overwrite << endl;
|
||
|
|
||
15 years ago
|
TQString src_name, src_path;
|
||
15 years ago
|
bool ok = m_impl.parseURL(src, src_name, src_path);
|
||
15 years ago
|
TQString dest_name, dest_path;
|
||
15 years ago
|
ok &= m_impl.parseURL(dest, dest_name, dest_path);
|
||
|
|
||
|
if ( ok && src_path.isEmpty() && dest_path.isEmpty()
|
||
|
&& src.protocol() == "media" && dest.protocol() == "media" )
|
||
|
{
|
||
|
if (!m_impl.setUserLabel(src_name, dest_name))
|
||
|
{
|
||
|
error(m_impl.lastErrorCode(), m_impl.lastErrorMessage());
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
finished();
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ForwardingSlaveBase::rename(src, dest, overwrite);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void MediaProtocol::mkdir(const KURL &url, int permissions)
|
||
|
{
|
||
|
kdDebug(1219) << "MediaProtocol::mkdir: " << url << endl;
|
||
|
|
||
15 years ago
|
TQString name, path;
|
||
15 years ago
|
bool ok = m_impl.parseURL(url, name, path);
|
||
|
|
||
|
if ( ok && path.isEmpty() )
|
||
|
{
|
||
12 years ago
|
error(TDEIO::ERR_COULD_NOT_MKDIR, url.prettyURL());
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
ForwardingSlaveBase::mkdir(url, permissions);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void MediaProtocol::del(const KURL &url, bool isFile)
|
||
|
{
|
||
|
kdDebug(1219) << "MediaProtocol::del: " << url << endl;
|
||
|
|
||
15 years ago
|
TQString name, path;
|
||
15 years ago
|
bool ok = m_impl.parseURL(url, name, path);
|
||
|
|
||
|
if ( ok && path.isEmpty() )
|
||
|
{
|
||
12 years ago
|
error(TDEIO::ERR_CANNOT_DELETE, url.prettyURL());
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
ForwardingSlaveBase::del(url, isFile);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void MediaProtocol::stat(const KURL &url)
|
||
|
{
|
||
|
kdDebug(1219) << "MediaProtocol::stat: " << url << endl;
|
||
15 years ago
|
TQString path = url.path();
|
||
15 years ago
|
if( path.isEmpty() || path == "/" )
|
||
|
{
|
||
|
// The root is "virtual" - it's not a single physical directory
|
||
12 years ago
|
TDEIO::UDSEntry entry;
|
||
15 years ago
|
m_impl.createTopLevelEntry( entry );
|
||
|
statEntry( entry );
|
||
|
finished();
|
||
|
return;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString name;
|
||
15 years ago
|
bool ok = m_impl.parseURL(url, name, path);
|
||
|
|
||
|
if ( !ok )
|
||
|
{
|
||
12 years ago
|
error(TDEIO::ERR_MALFORMED_URL, url.prettyURL());
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
if( path.isEmpty() )
|
||
|
{
|
||
12 years ago
|
TDEIO::UDSEntry entry;
|
||
15 years ago
|
|
||
|
if ( m_impl.statMedium(name, entry)
|
||
|
|| m_impl.statMediumByLabel(name, entry) )
|
||
|
{
|
||
|
statEntry(entry);
|
||
|
finished();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
12 years ago
|
error(TDEIO::ERR_DOES_NOT_EXIST, url.prettyURL());
|
||
15 years ago
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ForwardingSlaveBase::stat(url);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void MediaProtocol::listDir(const KURL &url)
|
||
|
{
|
||
|
kdDebug(1219) << "MediaProtocol::listDir: " << url << endl;
|
||
|
|
||
|
if ( url.path().length() <= 1 )
|
||
|
{
|
||
|
listRoot();
|
||
|
return;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString name, path;
|
||
15 years ago
|
bool ok = m_impl.parseURL(url, name, path);
|
||
|
|
||
|
if ( !ok )
|
||
|
{
|
||
12 years ago
|
error(TDEIO::ERR_MALFORMED_URL, url.prettyURL());
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
ForwardingSlaveBase::listDir(url);
|
||
|
}
|
||
|
|
||
|
void MediaProtocol::listRoot()
|
||
|
{
|
||
12 years ago
|
TDEIO::UDSEntry entry;
|
||
15 years ago
|
|
||
12 years ago
|
TDEIO::UDSEntryList media_entries;
|
||
15 years ago
|
bool ok = m_impl.listMedia(media_entries);
|
||
|
|
||
|
if (!ok)
|
||
|
{
|
||
|
error( m_impl.lastErrorCode(), m_impl.lastErrorMessage() );
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
totalSize(media_entries.count()+1);
|
||
|
|
||
|
m_impl.createTopLevelEntry(entry);
|
||
|
listEntry(entry, false);
|
||
|
|
||
12 years ago
|
TDEIO::UDSEntryListIterator it = media_entries.begin();
|
||
|
TDEIO::UDSEntryListIterator end = media_entries.end();
|
||
15 years ago
|
|
||
|
for(; it!=end; ++it)
|
||
|
{
|
||
|
listEntry(*it, false);
|
||
|
}
|
||
|
|
||
|
entry.clear();
|
||
|
listEntry(entry, true);
|
||
|
|
||
|
finished();
|
||
|
}
|
||
|
|
||
15 years ago
|
void MediaProtocol::slotWarning( const TQString &msg )
|
||
15 years ago
|
{
|
||
|
warning( msg );
|
||
|
}
|
||
|
|
||
12 years ago
|
#include "tdeio_media.moc"
|