~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to parts/copyto/copyto_part.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2004 by Jens Dagerbo                                    *
 
3
 *   jens.dagerbo@swipnet.se                                               *
 
4
 *                                                                         *
 
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.                                   *
 
9
 *                                                                         *
 
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.                          *
 
14
 *                                                                         *
 
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
 ***************************************************************************/
 
20
 
 
21
#include <qwhatsthis.h>
 
22
#include <qlistbox.h>
 
23
#include <qpopupmenu.h>
 
24
#include <qstring.h>
 
25
#include <qstringlist.h>
 
26
#include <qradiobutton.h>
 
27
 
 
28
#include <kiconloader.h>
 
29
#include <klocale.h>
 
30
#include <klineedit.h>
 
31
#include <kio/netaccess.h>
 
32
 
 
33
#include <kdevgenericfactory.h>
 
34
#include <kdevcore.h>
 
35
#include <kdevmainwindow.h>
 
36
#include <kdevproject.h>
 
37
#include <kdevplugininfo.h>
 
38
 
 
39
#include "copyto_part.h"
 
40
#include "copytodialog.h"
 
41
 
 
42
static const KDevPluginInfo data("kdevcopyto");
 
43
 
 
44
typedef KDevGenericFactory<CopyToPart> CopyToFactory;
 
45
K_EXPORT_COMPONENT_FACTORY( libkdevcopyto, CopyToFactory( data ) );
 
46
 
 
47
CopyToPart::CopyToPart(QObject *parent, const char *name, const QStringList& )
 
48
  : KDevPlugin(&data, parent, name ? name : "CopyToPart" )
 
49
{
 
50
        setInstance(CopyToFactory::instance());
 
51
//      setXMLFile("kdevpart_copyto.rc");
 
52
 
 
53
        connect( core(), SIGNAL(contextMenu(QPopupMenu*, const Context* )), this, SLOT(contextMenu(QPopupMenu*, const Context* )) );  
 
54
}
 
55
 
 
56
 
 
57
CopyToPart::~CopyToPart()
 
58
{
 
59
}
 
60
 
 
61
void CopyToPart::contextMenu( QPopupMenu * popup, const Context * context )
 
62
{
 
63
        if ( context->hasType( Context::FileContext ) )
 
64
        {
 
65
                popup->insertItem( i18n( "Copy To..." ), this, SLOT(doCopy()) );
 
66
                
 
67
                const FileContext * fContext = static_cast<const FileContext*>( context );
 
68
                _fileList = fContext->urls();
 
69
        }
 
70
        
 
71
}
 
72
 
 
73
void CopyToPart::doCopy( )
 
74
{
 
75
        QStringList files;
 
76
        
 
77
        KURL::List::Iterator it = _fileList.begin();
 
78
        while( it != _fileList.end() )
 
79
        {
 
80
                QString file = relativeProjectPath( (*it).path() );
 
81
                if ( !file.isEmpty() )
 
82
                {
 
83
                        files << file;
 
84
                }
 
85
                ++it;
 
86
        }
 
87
        
 
88
        if ( files.isEmpty() ) return;
 
89
        
 
90
        CopyToDialog dlg;
 
91
        dlg.fileList->insertStringList( files );
 
92
        
 
93
        if ( dlg.exec() == QDialog::Rejected ) return;
 
94
        
 
95
        KURL desturl = KURL::fromPathOrURL( dlg.url_line->text() );
 
96
        
 
97
        if ( !desturl.isValid() || !KIO::NetAccess::exists( desturl, true, 0 ) ) return;
 
98
        
 
99
        if ( dlg.traditional->isOn() )
 
100
        {
 
101
                it = _fileList.begin();
 
102
                while( it != _fileList.end() )
 
103
                {
 
104
                        KURL dest = KURL::fromPathOrURL( desturl.url( +1 ) + (*it).fileName() );
 
105
                        KIO::NetAccess::upload( (*it).path(), dest, 0 );
 
106
                        ++it;
 
107
                }
 
108
        }
 
109
        else
 
110
        {
 
111
                QStringList::Iterator it = files.begin();
 
112
                while( it != files.end() )
 
113
                {
 
114
                        KURL dest = KURL::fromPathOrURL( desturl.url( +1 ) + *it );
 
115
                        KIO::NetAccess::upload( project()->projectDirectory() + "/" + *it, dest, 0 );
 
116
                        ++it;
 
117
                }
 
118
        }
 
119
        
 
120
}
 
121
 
 
122
QString CopyToPart::relativeProjectPath( QString path )
 
123
{
 
124
        QString projectpath = project()->projectDirectory() + "/";
 
125
        if ( path.left( projectpath.length() ) == projectpath )
 
126
        {
 
127
                path = path.mid( projectpath.length() );
 
128
                return path;
 
129
        }
 
130
        return QString::null;
 
131
}
 
132
 
 
133
#include "copyto_part.moc"