1
/***************************************************************************
2
* Copyright (C) 2004 by Jens Dagerbo *
3
* jens.dagerbo@swipnet.se *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
21
#include <qwhatsthis.h>
23
#include <qpopupmenu.h>
25
#include <qstringlist.h>
26
#include <qradiobutton.h>
28
#include <kiconloader.h>
30
#include <klineedit.h>
31
#include <kio/netaccess.h>
33
#include <kdevgenericfactory.h>
35
#include <kdevmainwindow.h>
36
#include <kdevproject.h>
37
#include <kdevplugininfo.h>
39
#include "copyto_part.h"
40
#include "copytodialog.h"
42
static const KDevPluginInfo data("kdevcopyto");
44
typedef KDevGenericFactory<CopyToPart> CopyToFactory;
45
K_EXPORT_COMPONENT_FACTORY( libkdevcopyto, CopyToFactory( data ) );
47
CopyToPart::CopyToPart(QObject *parent, const char *name, const QStringList& )
48
: KDevPlugin(&data, parent, name ? name : "CopyToPart" )
50
setInstance(CopyToFactory::instance());
51
// setXMLFile("kdevpart_copyto.rc");
53
connect( core(), SIGNAL(contextMenu(QPopupMenu*, const Context* )), this, SLOT(contextMenu(QPopupMenu*, const Context* )) );
57
CopyToPart::~CopyToPart()
61
void CopyToPart::contextMenu( QPopupMenu * popup, const Context * context )
63
if ( context->hasType( Context::FileContext ) )
65
popup->insertItem( i18n( "Copy To..." ), this, SLOT(doCopy()) );
67
const FileContext * fContext = static_cast<const FileContext*>( context );
68
_fileList = fContext->urls();
73
void CopyToPart::doCopy( )
77
KURL::List::Iterator it = _fileList.begin();
78
while( it != _fileList.end() )
80
QString file = relativeProjectPath( (*it).path() );
81
if ( !file.isEmpty() )
88
if ( files.isEmpty() ) return;
91
dlg.fileList->insertStringList( files );
93
if ( dlg.exec() == QDialog::Rejected ) return;
95
KURL desturl = KURL::fromPathOrURL( dlg.url_line->text() );
97
if ( !desturl.isValid() || !KIO::NetAccess::exists( desturl, true, 0 ) ) return;
99
if ( dlg.traditional->isOn() )
101
it = _fileList.begin();
102
while( it != _fileList.end() )
104
KURL dest = KURL::fromPathOrURL( desturl.url( +1 ) + (*it).fileName() );
105
KIO::NetAccess::upload( (*it).path(), dest, 0 );
111
QStringList::Iterator it = files.begin();
112
while( it != files.end() )
114
KURL dest = KURL::fromPathOrURL( desturl.url( +1 ) + *it );
115
KIO::NetAccess::upload( project()->projectDirectory() + "/" + *it, dest, 0 );
122
QString CopyToPart::relativeProjectPath( QString path )
124
QString projectpath = project()->projectDirectory() + "/";
125
if ( path.left( projectpath.length() ) == projectpath )
127
path = path.mid( projectpath.length() );
130
return QString::null;
133
#include "copyto_part.moc"