KDevelop API Documentation

fileselectorwidget.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002  *   Copyright (C) 2001 by Hugo Varotto                                     *
00003  *   hugo@varotto-usa.com                                                   *
00004  *                                                                          *
00005  *   Based on Kate's fileselector widget    by                                  *
00006  *          Matt Newell                                                     *
00007  *          (C) 2001 by Matt Newell                                         *
00008  *          newellm@proaxis.com                                             *
00009  *                                                                          *
00010  *   This program is free software; you can redistribute it and/or modify       *
00011  *   it under the terms of the GNU General Public License as published by       *
00012  *   the Free Software Foundation; either version 2 of the License, or          *
00013  *   (at your option) any later version                                     *
00014  *                                                                          *
00015  ***************************************************************************/
00016 
00017 #include <qlayout.h>
00018 #include <qpushbutton.h>
00019 #include <qhbox.h>
00020 #include <qlabel.h>
00021 #include <qstrlist.h>
00022 #include <qtooltip.h>
00023 #include <qregexp.h>
00024 
00025 #include <kiconloader.h>
00026 #include <kurlcombobox.h>
00027 #include <kurlcompletion.h>
00028 #include <kprotocolinfo.h>
00029 #include <kconfig.h>
00030 #include <klocale.h>
00031 #include <kcombobox.h>
00032 
00033 #include <kdebug.h>
00034 
00035 #include "fileselectorwidget.h"
00036 #include <kdiroperator.h>
00037 #include <kcombiview.h>
00038 #include <kfilepreview.h>
00039 #include <kfileview.h>
00040 #include <kfileitem.h>
00041 #include <kimagefilepreview.h>
00042 
00043 #include "autoprojectwidget.h"
00044 #include "autoprojectpart.h"
00045 #include "kdevlanguagesupport.h"
00046 
00047 #include "kfilednddetailview.h"
00048 #include "kfiledndiconview.h"
00049 
00050 KDnDDirOperator::KDnDDirOperator ( const KURL &urlName, QWidget* parent, const char* name ) : KDirOperator ( urlName, parent, name )
00051 {
00052 
00053 }
00054 
00055 KFileView* KDnDDirOperator::createView( QWidget* parent, KFile::FileView view )
00056 {
00057     KFileView* new_view = 0L;
00058 
00059     if( (view & KFile::Detail) == KFile::Detail ) {
00060         new_view = new KFileDnDDetailView( parent, "detail view");
00061     }
00062     else if ((view & KFile::Simple) == KFile::Simple ) {
00063         new_view = new KFileDnDIconView( parent, "simple view");
00064         new_view->setViewName( i18n("Short View") );
00065     }
00066 
00067     return new_view;
00068 }
00069 
00070 
00071 FileSelectorWidget::FileSelectorWidget(AutoProjectPart* part, KFile::Mode mode, QWidget* parent, const char* name ) : QWidget(parent, name)
00072 {
00073     m_part = part;
00074 
00075     // widgets and layout
00076     QVBoxLayout* lo = new QVBoxLayout(this);
00077 
00078     QHBox *hlow = new QHBox (this);
00079     lo->addWidget(hlow);
00080 
00081     home = new QPushButton( hlow );
00082     home->setPixmap(SmallIcon("gohome"));
00083     QToolTip::add(home, i18n("Home directory"));
00084     up = new QPushButton( /*i18n("&Up"),*/ hlow );
00085     up->setPixmap(SmallIcon("up"));
00086     QToolTip::add(up, i18n("Up one level"));
00087     back = new QPushButton( /*i18n("&Back"),*/ hlow );
00088     back->setPixmap(SmallIcon("back"));
00089     QToolTip::add(back, i18n("Previous directory"));
00090     forward = new QPushButton( /*i18n("&Next"),*/ hlow );
00091     forward->setPixmap(SmallIcon("forward"));
00092     QToolTip::add(forward, i18n("Next directory"));
00093 
00094     // HACK
00095     QWidget* spacer = new QWidget(hlow);
00096     hlow->setStretchFactor(spacer, 1);
00097     hlow->setMaximumHeight(up->height());
00098 
00099     cmbPath = new KURLComboBox( KURLComboBox::Directories, true, this, "path combo" );
00100     cmbPath->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ));
00101     KURLCompletion* cmpl = new KURLCompletion();
00102     cmbPath->setCompletionObject( cmpl );
00103     lo->addWidget(cmbPath);
00104 
00105     dir = new KDnDDirOperator(KURL(), this, "operator");
00106     dir->setView(KFile::Simple);
00107     dir->setMode(mode);
00108 
00109     lo->addWidget(dir);
00110     lo->setStretchFactor(dir, 2);
00111 
00112     QHBox* filterBox = new QHBox(this);
00113     filterIcon = new QLabel(filterBox);
00114     filterIcon->setPixmap( BarIcon("filter") );
00115     filter = new KHistoryCombo(filterBox, "filter");
00116     filter->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ));
00117     filterBox->setStretchFactor(filter, 2);
00118     lo->addWidget(filterBox);
00119 
00120     // slots and signals
00121     connect( filter, SIGNAL( activated(const QString&) ), SLOT( slotFilterChanged(const QString&) ) );
00122     connect( filter, SIGNAL( returnPressed(const QString&) ), SLOT( filterReturnPressed(const QString&) ) );
00123 
00124     connect( home, SIGNAL( clicked() ), dir, SLOT( home() ) );
00125     connect( up, SIGNAL( clicked() ), dir, SLOT( cdUp() ) );
00126     connect( back, SIGNAL( clicked() ), dir, SLOT( back() ) );
00127     connect( forward, SIGNAL( clicked() ), dir, SLOT( forward() ) );
00128 
00129     connect( cmbPath, SIGNAL( urlActivated( const KURL&  )), this,  SLOT( cmbPathActivated( const KURL& ) ));
00130     connect( cmbPath, SIGNAL( returnPressed( const QString&  )), this,  SLOT( cmbPathReturnPressed( const QString& ) ));
00131     connect( dir, SIGNAL(urlEntered(const KURL&)), this, SLOT(dirUrlEntered(const KURL&)) );
00132 
00133     connect( dir, SIGNAL(finishedLoading()), this, SLOT(dirFinishedLoading()) );
00134 
00135 //    dirUrlEntered( dir->url() );
00136 
00137     QStringList list;
00138 
00139     /* read the file patterns from the project DOM */
00140     QDomElement docEl = m_part->projectDom()->documentElement();
00141     QDomElement fileviewEl = docEl.namedItem("kdevfileview").toElement();
00142     QDomElement groupsEl = fileviewEl.namedItem("groups").toElement();
00143     QDomElement groupEl = groupsEl.firstChild().toElement();
00144 
00145     while ( !groupEl.isNull() )
00146     {
00147         if (groupEl.tagName() == "group")
00148         {
00149             list << groupEl.attribute("pattern").replace ( QRegExp ( ";" ), " " ) + " (" + groupEl.attribute("name") + ")";
00150         }
00151         groupEl = groupEl.nextSibling().toElement();
00152     }
00153 
00154     filter->setHistoryItems ( list );
00155 
00156 //    dir->rereadDir();
00157 }
00158 
00159 
00160 FileSelectorWidget::~FileSelectorWidget()
00161 {
00162 }
00163 
00164 void FileSelectorWidget::dragEnterEvent ( QDragEnterEvent* /*ev*/ )
00165 {
00166 }
00167 
00168 void FileSelectorWidget::dropEvent ( QDropEvent* /*ev*/ )
00169 {
00170     kdDebug ( 9000 ) << "Dropped" << endl;
00171 
00172     QString path = "Something was dropped in the Destination directory file-selector";
00173 
00174     emit dropped ( path );
00175 
00176 }
00177 
00178 void FileSelectorWidget::filterReturnPressed ( const QString& nf )
00179 {
00180     // KURL u ( m_part->project()->projectDirectory() );
00181     setDir ( nf );
00182 }
00183 
00184 void FileSelectorWidget::slotFilterChanged( const QString & nf )
00185 {
00186   dir->setNameFilter( nf );
00187   dir->rereadDir();
00188 }
00189 
00190 void FileSelectorWidget::cmbPathActivated( const KURL& u )
00191 {
00192    dir->setURL( u, true );
00193 }
00194 
00195 void FileSelectorWidget::cmbPathReturnPressed( const QString& u )
00196 {
00197    dir->setFocus();
00198    dir->setURL( KURL(u), true );
00199 }
00200 
00201 
00202 void FileSelectorWidget::dirUrlEntered( const KURL& u )
00203 {
00204    cmbPath->removeURL( u );
00205    QStringList urls = cmbPath->urls();
00206    urls.prepend( u.url() );
00207    while ( urls.count() >= (uint)cmbPath->maxItems() )
00208       urls.remove( urls.last() );
00209    cmbPath->setURLs( urls );
00210 }
00211 
00212 
00213 void FileSelectorWidget::dirFinishedLoading()
00214 {
00215    // HACK - enable the nav buttons
00216    // have to wait for diroperator...
00217    up->setEnabled( dir->actionCollection()->action( "up" )->isEnabled() );
00218    back->setEnabled( dir->actionCollection()->action( "back" )->isEnabled() );
00219    forward->setEnabled( dir->actionCollection()->action( "forward" )->isEnabled() );
00220    home->setEnabled( dir->actionCollection()->action( "home" )->isEnabled() );
00221 }
00222 
00223 
00224 void FileSelectorWidget::focusInEvent(QFocusEvent*)
00225 {
00226    dir->setFocus();
00227 }
00228 
00229 void FileSelectorWidget::setDir( KURL u )
00230 {
00231   dir->setURL(u, true);
00232 }
00233 
00234 void FileSelectorWidget::setDir(const QString& path)
00235 {
00236     KURL u ( path );
00237     dir->setURL ( u, true );
00238 }
00239 
00240 
00241 #include "fileselectorwidget.moc"
00242 
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 00:03:39 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003