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

« back to all changes in this revision

Viewing changes to buildtools/autotools/fileselectorwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
 *   Copyright (C) 2001 by Hugo Varotto                                                                         *
3
 
 *   hugo@varotto-usa.com                                                                                                       *
4
 
 *                                                                                                                                                      *
5
 
 *       Based on Kate's fileselector widget    by                                                                      *
6
 
 *          Matt Newell                                                                                                         *
7
 
 *                      (C) 2001 by Matt Newell                                                                                 *
8
 
 *                      newellm@proaxis.com                                                                                             *
9
 
 *                                                                                                                                                      *
10
 
 *   This program is free software; you can redistribute it and/or modify               *
11
 
 *   it under the terms of the GNU General Public License as published by               *
12
 
 *   the Free Software Foundation; either version 2 of the License, or                  *
13
 
 *   (at your option) any later version                                                                         *
14
 
 *                                                                                                                                                      *
15
 
 ***************************************************************************/
16
 
 
17
 
#include <qlayout.h>
18
 
#include <qpushbutton.h>
19
 
#include <qhbox.h>
20
 
#include <qlabel.h>
21
 
#include <qstrlist.h>
22
 
#include <qtooltip.h>
23
 
#include <qregexp.h>
24
 
 
25
 
#include <kxmlguiclient.h>
26
 
#include <kiconloader.h>
27
 
#include <kurlcombobox.h>
28
 
#include <kurlcompletion.h>
29
 
#include <kprotocolinfo.h>
30
 
#include <kconfig.h>
31
 
#include <klocale.h>
32
 
#include <kcombobox.h>
33
 
 
34
 
#include <kdebug.h>
35
 
 
36
 
#include "fileselectorwidget.h"
37
 
#include <kdiroperator.h>
38
 
#include <kcombiview.h>
39
 
#include <kfilepreview.h>
40
 
#include <kfileview.h>
41
 
#include <kfileitem.h>
42
 
#include <kimagefilepreview.h>
43
 
 
44
 
#include "autoprojectwidget.h"
45
 
#include "autoprojectpart.h"
46
 
#include "kdevlanguagesupport.h"
47
 
 
48
 
#include "kfilednddetailview.h"
49
 
#include "kfiledndiconview.h"
50
 
 
51
 
KDnDDirOperator::KDnDDirOperator ( const KURL &urlName, QWidget* parent, const char* name ) : KDirOperator ( urlName, parent, name )
52
 
{
53
 
 
54
 
}
55
 
 
56
 
KFileView* KDnDDirOperator::createView( QWidget* parent, KFile::FileView view )
57
 
{
58
 
    KFileView* new_view = 0L;
59
 
 
60
 
    if( (view & KFile::Detail) == KFile::Detail ) {
61
 
        new_view = new KFileDnDDetailView( parent, "detail view");
62
 
    }
63
 
    else if ((view & KFile::Simple) == KFile::Simple ) {
64
 
        new_view = new KFileDnDIconView( parent, "simple view");
65
 
        new_view->setViewName( i18n("Short View") );
66
 
    }
67
 
 
68
 
    return new_view;
69
 
}
70
 
 
71
 
 
72
 
FileSelectorWidget::FileSelectorWidget(AutoProjectPart* part, KFile::Mode mode, QWidget* parent, const char* name ) : QWidget(parent, name)
73
 
{
74
 
    m_part = part;
75
 
 
76
 
        // widgets and layout
77
 
        QVBoxLayout* lo = new QVBoxLayout(this);
78
 
 
79
 
        QHBox *hlow = new QHBox (this);
80
 
        lo->addWidget(hlow);
81
 
 
82
 
        home = new QPushButton( hlow );
83
 
        home->setPixmap(SmallIcon("gohome"));
84
 
        QToolTip::add(home, i18n("Home directory"));
85
 
        up = new QPushButton( /*i18n("&Up"),*/ hlow );
86
 
        up->setPixmap(SmallIcon("up"));
87
 
        QToolTip::add(up, i18n("Up one level"));
88
 
        back = new QPushButton( /*i18n("&Back"),*/ hlow );
89
 
        back->setPixmap(SmallIcon("back"));
90
 
        QToolTip::add(back, i18n("Previous directory"));
91
 
        forward = new QPushButton( /*i18n("&Next"),*/ hlow );
92
 
        forward->setPixmap(SmallIcon("forward"));
93
 
        QToolTip::add(forward, i18n("Next directory"));
94
 
 
95
 
        // HACK
96
 
        QWidget* spacer = new QWidget(hlow);
97
 
        hlow->setStretchFactor(spacer, 1);
98
 
        hlow->setMaximumHeight(up->height());
99
 
 
100
 
        cmbPath = new KURLComboBox( KURLComboBox::Directories, true, this, "path combo" );
101
 
        cmbPath->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ));
102
 
        KURLCompletion* cmpl = new KURLCompletion();
103
 
        cmbPath->setCompletionObject( cmpl );
104
 
        lo->addWidget(cmbPath);
105
 
 
106
 
        dir = new KDnDDirOperator(KURL(), this, "operator");
107
 
        dir->setView(KFile::Simple);
108
 
    dir->setMode(mode);
109
 
 
110
 
        lo->addWidget(dir);
111
 
        lo->setStretchFactor(dir, 2);
112
 
 
113
 
        QHBox* filterBox = new QHBox(this);
114
 
        filterIcon = new QLabel(filterBox);
115
 
        filterIcon->setPixmap( BarIcon("filter") );
116
 
        filter = new KHistoryCombo(filterBox, "filter");
117
 
        filter->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ));
118
 
        filterBox->setStretchFactor(filter, 2);
119
 
        lo->addWidget(filterBox);
120
 
 
121
 
        // slots and signals
122
 
        connect( filter, SIGNAL( textChanged(const QString&) ), SLOT( slotFilterChanged(const QString&) ) );
123
 
        connect( filter, SIGNAL( activated(const QString&) ), SLOT( slotFilterChanged(const QString&) ) );
124
 
        connect( filter, SIGNAL( returnPressed(const QString&) ), SLOT( filterReturnPressed(const QString&) ) );
125
 
 
126
 
        connect( home, SIGNAL( clicked() ), dir, SLOT( home() ) );
127
 
        connect( up, SIGNAL( clicked() ), dir, SLOT( cdUp() ) );
128
 
        connect( back, SIGNAL( clicked() ), dir, SLOT( back() ) );
129
 
        connect( forward, SIGNAL( clicked() ), dir, SLOT( forward() ) );
130
 
 
131
 
        connect( cmbPath, SIGNAL( urlActivated( const KURL&  )), this,  SLOT( cmbPathActivated( const KURL& ) ));
132
 
        //connect( cmbPath, SIGNAL( returnPressed( const QString&  )), this,  SLOT( cmbPathReturnPressed( const QString& ) ));
133
 
        connect( dir, SIGNAL(urlEntered(const KURL&)), this, SLOT(dirUrlEntered(const KURL&)) );
134
 
 
135
 
        connect( dir, SIGNAL(finishedLoading()), this, SLOT(dirFinishedLoading()) );
136
 
 
137
 
//    dirUrlEntered( dir->url() );
138
 
 
139
 
    QStringList list;
140
 
 
141
 
    /* read the file patterns from the project DOM */
142
 
    QDomElement docEl = m_part->projectDom()->documentElement();
143
 
    QDomElement fileviewEl = docEl.namedItem("kdevfileview").toElement();
144
 
    QDomElement groupsEl = fileviewEl.namedItem("groups").toElement();
145
 
    QDomElement groupEl = groupsEl.firstChild().toElement();
146
 
 
147
 
    while ( !groupEl.isNull() )
148
 
    {
149
 
        if (groupEl.tagName() == "group")
150
 
        {
151
 
            list << groupEl.attribute("pattern").replace ( QRegExp ( ";" ), " " ) + " (" + groupEl.attribute("name") + ")";
152
 
        }
153
 
        groupEl = groupEl.nextSibling().toElement();
154
 
    }
155
 
 
156
 
    filter->setHistoryItems ( list );
157
 
 
158
 
}
159
 
 
160
 
 
161
 
FileSelectorWidget::~FileSelectorWidget()
162
 
{
163
 
}
164
 
 
165
 
void FileSelectorWidget::dragEnterEvent ( QDragEnterEvent* /*ev*/ )
166
 
{
167
 
}
168
 
 
169
 
void FileSelectorWidget::dropEvent ( QDropEvent* /*ev*/ )
170
 
{
171
 
    kdDebug ( 9020 ) << "Dropped" << endl;
172
 
 
173
 
    QString path = "Something was dropped in the Destination directory file-selector";
174
 
 
175
 
    emit dropped ( path );
176
 
 
177
 
}
178
 
 
179
 
void FileSelectorWidget::filterReturnPressed ( const QString& nf )
180
 
{
181
 
    // KURL u ( m_part->project()->projectDirectory() );
182
 
    setDir ( nf );
183
 
}
184
 
 
185
 
void FileSelectorWidget::slotFilterChanged( const QString & nf )
186
 
{
187
 
  dir->setNameFilter( nf );
188
 
  dir->updateDir();
189
 
}
190
 
 
191
 
void FileSelectorWidget::cmbPathActivated( const KURL& u )
192
 
{
193
 
   dir->setURL( u, true );
194
 
}
195
 
 
196
 
void FileSelectorWidget::cmbPathReturnPressed( const QString& u )
197
 
{
198
 
   dir->setFocus();
199
 
   dir->setURL( KURL(u), true );
200
 
}
201
 
 
202
 
 
203
 
void FileSelectorWidget::dirUrlEntered( const KURL& u )
204
 
{
205
 
   cmbPath->removeURL( u );
206
 
   QStringList urls = cmbPath->urls();
207
 
   urls.prepend( u.url() );
208
 
   while ( urls.count() >= (uint)cmbPath->maxItems() )
209
 
      urls.remove( urls.last() );
210
 
   cmbPath->setURLs( urls );
211
 
}
212
 
 
213
 
 
214
 
void FileSelectorWidget::dirFinishedLoading()
215
 
{
216
 
   // HACK - enable the nav buttons
217
 
   // have to wait for diroperator...
218
 
   up->setEnabled( dir->actionCollection()->action( "up" )->isEnabled() );
219
 
   back->setEnabled( dir->actionCollection()->action( "back" )->isEnabled() );
220
 
   forward->setEnabled( dir->actionCollection()->action( "forward" )->isEnabled() );
221
 
   home->setEnabled( dir->actionCollection()->action( "home" )->isEnabled() );
222
 
}
223
 
 
224
 
 
225
 
void FileSelectorWidget::focusInEvent(QFocusEvent*)
226
 
{
227
 
   dir->setFocus();
228
 
}
229
 
 
230
 
void FileSelectorWidget::setDir( KURL u )
231
 
{
232
 
  dir->setURL(u, true);
233
 
}
234
 
 
235
 
void FileSelectorWidget::setDir(const QString& path)
236
 
{
237
 
    KURL u ( path );
238
 
    dir->setURL ( u, true );
239
 
}
240
 
 
241
 
 
242
 
#include "fileselectorwidget.moc"
243