copyto_part.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qwhatsthis.h>
00022 #include <qlistbox.h>
00023 #include <qpopupmenu.h>
00024 #include <qstring.h>
00025 #include <qstringlist.h>
00026 #include <qradiobutton.h>
00027
00028 #include <kiconloader.h>
00029 #include <klocale.h>
00030 #include <klineedit.h>
00031 #include <kio/netaccess.h>
00032
00033 #include <kdevgenericfactory.h>
00034 #include <kdevcore.h>
00035 #include <kdevmainwindow.h>
00036 #include <kdevproject.h>
00037
00038
00039 #include "copyto_part.h"
00040 #include "copytodialog.h"
00041
00042 static const KAboutData data("kdevcopyto", I18N_NOOP("Copy To..."), "1.0");
00043
00044 typedef KDevGenericFactory<CopyToPart> CopyToFactory;
00045 K_EXPORT_COMPONENT_FACTORY( libkdevcopyto, CopyToFactory( &data ) );
00046
00047 CopyToPart::CopyToPart(QObject *parent, const char *name, const QStringList& )
00048 : KDevPlugin("copyto", "copyto", parent, name ? name : "CopyToPart" )
00049 {
00050 setInstance(CopyToFactory::instance());
00051
00052
00053 connect( core(), SIGNAL(contextMenu(QPopupMenu*, const Context* )), this, SLOT(contextMenu(QPopupMenu*, const Context* )) );
00054 }
00055
00056
00057 CopyToPart::~CopyToPart()
00058 {
00059 }
00060
00061 void CopyToPart::contextMenu( QPopupMenu * popup, const Context * context )
00062 {
00063 if ( context->hasType( Context::FileContext ) )
00064 {
00065 popup->insertItem( i18n( "Copy To..." ), this, SLOT(doCopy()) );
00066
00067 const FileContext * fContext = static_cast<const FileContext*>( context );
00068 _fileList = fContext->urls();
00069 }
00070
00071 }
00072
00073 void CopyToPart::doCopy( )
00074 {
00075 QStringList files;
00076
00077 KURL::List::Iterator it = _fileList.begin();
00078 while( it != _fileList.end() )
00079 {
00080 QString file = relativeProjectPath( (*it).path() );
00081 if ( !file.isEmpty() )
00082 {
00083 files << file;
00084 }
00085 ++it;
00086 }
00087
00088 if ( files.isEmpty() ) return;
00089
00090 CopyToDialog dlg;
00091 dlg.fileList->insertStringList( files );
00092
00093 if ( dlg.exec() == QDialog::Rejected ) return;
00094
00095 KURL desturl = KURL::fromPathOrURL( dlg.url_line->text() );
00096
00097 if ( !desturl.isValid() || !KIO::NetAccess::exists( desturl, true, 0 ) ) return;
00098
00099 if ( dlg.traditional->isOn() )
00100 {
00101 it = _fileList.begin();
00102 while( it != _fileList.end() )
00103 {
00104 KURL dest = KURL::fromPathOrURL( desturl.url( +1 ) + (*it).fileName() );
00105 KIO::NetAccess::upload( (*it).path(), dest, 0 );
00106 ++it;
00107 }
00108 }
00109 else
00110 {
00111 QStringList::Iterator it = files.begin();
00112 while( it != files.end() )
00113 {
00114 KURL dest = KURL::fromPathOrURL( desturl.url( +1 ) + *it );
00115 KIO::NetAccess::upload( project()->projectDirectory() + "/" + *it, dest, 0 );
00116 ++it;
00117 }
00118 }
00119
00120 }
00121
00122 QString CopyToPart::relativeProjectPath( QString path )
00123 {
00124 QString projectpath = project()->projectDirectory() + "/";
00125 if ( path.left( projectpath.length() ) == projectpath )
00126 {
00127 path = path.mid( projectpath.length() );
00128 return path;
00129 }
00130 return QString::null;
00131 }
00132
00133 #include "copyto_part.moc"
This file is part of the documentation for KDevelop Version 3.1.2.