~ubuntu-branches/ubuntu/lucid/kdebase/lucid

« back to all changes in this revision

Viewing changes to kioslave/media/kio_media.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-27 12:09:48 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080527120948-dottsyd5rcwhzd36
Tags: 4:4.0.80-1ubuntu1
* Merge with Debian
 - remove 97_fix_target_link_libraries.diff
 - Add replaces/conflicts on -kde4 packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE project
2
 
   Copyright (c) 2004 Kevin Ottens <ervin ipsquad net>
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; either
7
 
   version 2 of the License, or (at your option) any later version.
8
 
 
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.
13
 
 
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.
18
 
*/
19
 
 
20
 
#include <stdlib.h>
21
 
 
22
 
#include <kdebug.h>
23
 
#include <klocale.h>
24
 
#include <kapplication.h>
25
 
#include <dcopclient.h>
26
 
#include <kcmdlineargs.h>
27
 
 
28
 
#include <qeventloop.h>
29
 
 
30
 
#include "kio_media.h"
31
 
 
32
 
 
33
 
static const KCmdLineOptions options[] =
34
 
{
35
 
        { "+protocol", I18N_NOOP( "Protocol name" ), 0 },
36
 
        { "+pool", I18N_NOOP( "Socket name" ), 0 },
37
 
        { "+app", I18N_NOOP( "Socket name" ), 0 },
38
 
        KCmdLineLastOption
39
 
};
40
 
 
41
 
extern "C" {
42
 
        int KDE_EXPORT kdemain( int argc, char **argv )
43
 
        {
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();
51
 
 
52
 
                KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
53
 
                MediaProtocol slave( args->arg(0), args->arg(1), args->arg(2) );
54
 
                slave.dispatchLoop();
55
 
                return 0;
56
 
        }
57
 
}
58
 
 
59
 
 
60
 
MediaProtocol::MediaProtocol(const QCString &protocol,
61
 
                             const QCString &pool, const QCString &app)
62
 
        : ForwardingSlaveBase(protocol, pool, app)
63
 
{
64
 
        connect( &m_impl, SIGNAL( warning( const QString & ) ),
65
 
                 this, SLOT( slotWarning( const QString & ) ) );
66
 
}
67
 
 
68
 
MediaProtocol::~MediaProtocol()
69
 
{
70
 
}
71
 
 
72
 
bool MediaProtocol::rewriteURL(const KURL &url, KURL &newUrl)
73
 
{
74
 
        QString name, path;
75
 
 
76
 
        if ( !m_impl.parseURL(url, name, path) )
77
 
        {
78
 
                error(KIO::ERR_MALFORMED_URL, url.prettyURL());
79
 
                return false;
80
 
        }
81
 
 
82
 
 
83
 
        if ( !m_impl.realURL(name, path, newUrl) )
84
 
        {
85
 
                error( m_impl.lastErrorCode(), m_impl.lastErrorMessage() );
86
 
                return false;
87
 
        }
88
 
 
89
 
        return true;
90
 
}
91
 
 
92
 
void MediaProtocol::put(const KURL &url, int permissions,
93
 
                        bool overwrite, bool resume)
94
 
{
95
 
        kdDebug(1219) << "MediaProtocol::put: " << url << endl;
96
 
 
97
 
        QString name, path;
98
 
        bool ok = m_impl.parseURL(url, name, path);
99
 
 
100
 
        if ( ok && path.isEmpty() )
101
 
        {
102
 
                error(KIO::ERR_CANNOT_OPEN_FOR_WRITING, url.prettyURL());
103
 
        }
104
 
        else
105
 
        {
106
 
                ForwardingSlaveBase::put(url, permissions, overwrite, resume);
107
 
        }
108
 
}
109
 
 
110
 
void MediaProtocol::rename(const KURL &src, const KURL &dest, bool overwrite)
111
 
{
112
 
        kdDebug(1219) << "MediaProtocol::rename: " << src << ", " << dest << ", "
113
 
                  << overwrite << endl;
114
 
 
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);
119
 
 
120
 
        if ( ok && src_path.isEmpty() && dest_path.isEmpty()
121
 
          && src.protocol() == "media" && dest.protocol() == "media" )
122
 
        {
123
 
                if (!m_impl.setUserLabel(src_name, dest_name))
124
 
                {
125
 
                        error(m_impl.lastErrorCode(), m_impl.lastErrorMessage());
126
 
                }
127
 
                else
128
 
                {
129
 
                        finished();
130
 
                }
131
 
        }
132
 
        else
133
 
        {
134
 
                ForwardingSlaveBase::rename(src, dest, overwrite);
135
 
        }
136
 
}
137
 
 
138
 
void MediaProtocol::mkdir(const KURL &url, int permissions)
139
 
{
140
 
        kdDebug(1219) << "MediaProtocol::mkdir: " << url << endl;
141
 
 
142
 
        QString name, path;
143
 
        bool ok = m_impl.parseURL(url, name, path);
144
 
 
145
 
        if ( ok && path.isEmpty() )
146
 
        {
147
 
                error(KIO::ERR_COULD_NOT_MKDIR, url.prettyURL());
148
 
        }
149
 
        else
150
 
        {
151
 
                ForwardingSlaveBase::mkdir(url, permissions);
152
 
        }
153
 
}
154
 
 
155
 
void MediaProtocol::del(const KURL &url, bool isFile)
156
 
{
157
 
        kdDebug(1219) << "MediaProtocol::del: " << url << endl;
158
 
 
159
 
        QString name, path;
160
 
        bool ok = m_impl.parseURL(url, name, path);
161
 
 
162
 
        if ( ok && path.isEmpty() )
163
 
        {
164
 
                error(KIO::ERR_CANNOT_DELETE, url.prettyURL());
165
 
        }
166
 
        else
167
 
        {
168
 
                ForwardingSlaveBase::del(url, isFile);
169
 
        }
170
 
}
171
 
 
172
 
void MediaProtocol::stat(const KURL &url)
173
 
{
174
 
        kdDebug(1219) << "MediaProtocol::stat: " << url << endl;
175
 
        QString path = url.path();
176
 
        if( path.isEmpty() || path == "/" )
177
 
        {
178
 
                // The root is "virtual" - it's not a single physical directory
179
 
                KIO::UDSEntry entry;
180
 
                m_impl.createTopLevelEntry( entry );
181
 
                statEntry( entry );
182
 
                finished();
183
 
                return;
184
 
        }
185
 
 
186
 
        QString name;
187
 
        bool ok = m_impl.parseURL(url, name, path);
188
 
 
189
 
        if ( !ok )
190
 
        {
191
 
                error(KIO::ERR_MALFORMED_URL, url.prettyURL());
192
 
                return;
193
 
        }
194
 
 
195
 
        if( path.isEmpty() )
196
 
        {
197
 
                KIO::UDSEntry entry;
198
 
 
199
 
                if ( m_impl.statMedium(name, entry)
200
 
                  || m_impl.statMediumByLabel(name, entry) )
201
 
                {
202
 
                        statEntry(entry);
203
 
                        finished();
204
 
                }
205
 
                else
206
 
                {
207
 
                        error(KIO::ERR_DOES_NOT_EXIST, url.prettyURL());
208
 
                }
209
 
        }
210
 
        else
211
 
        {
212
 
                ForwardingSlaveBase::stat(url);
213
 
        }
214
 
}
215
 
 
216
 
void MediaProtocol::listDir(const KURL &url)
217
 
{
218
 
        kdDebug(1219) << "MediaProtocol::listDir: " << url << endl;
219
 
 
220
 
        if ( url.path().length() <= 1 )
221
 
        {
222
 
                listRoot();
223
 
                return;
224
 
        }
225
 
 
226
 
        QString name, path;
227
 
        bool ok = m_impl.parseURL(url, name, path);
228
 
 
229
 
        if ( !ok )
230
 
        {
231
 
                error(KIO::ERR_MALFORMED_URL, url.prettyURL());
232
 
                return;
233
 
        }
234
 
 
235
 
        ForwardingSlaveBase::listDir(url);
236
 
}
237
 
 
238
 
void MediaProtocol::listRoot()
239
 
{
240
 
        KIO::UDSEntry entry;
241
 
 
242
 
        KIO::UDSEntryList media_entries;
243
 
        bool ok = m_impl.listMedia(media_entries);
244
 
 
245
 
        if (!ok)
246
 
        {
247
 
                error( m_impl.lastErrorCode(), m_impl.lastErrorMessage() );
248
 
                return;
249
 
        }
250
 
 
251
 
        totalSize(media_entries.count()+1);
252
 
 
253
 
        m_impl.createTopLevelEntry(entry);
254
 
        listEntry(entry, false);
255
 
 
256
 
        KIO::UDSEntryListIterator it = media_entries.begin();
257
 
        KIO::UDSEntryListIterator end = media_entries.end();
258
 
 
259
 
        for(; it!=end; ++it)
260
 
        {
261
 
                listEntry(*it, false);
262
 
        }
263
 
 
264
 
        entry.clear();
265
 
        listEntry(entry, true);
266
 
 
267
 
        finished();
268
 
}
269
 
 
270
 
void MediaProtocol::slotWarning( const QString &msg )
271
 
{
272
 
        warning( msg );
273
 
}
274
 
 
275
 
#include "kio_media.moc"