konq_listview.cc 24.1 KB
Newer Older
1
2
/* This file is part of the KDE project
   Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3

4
5
   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
6
7
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
8

9
   This program is distributed in the hope that it will be useful,
10
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
    General Public License for more details.
13

14
15
   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
Dirk Mueller's avatar
Dirk Mueller committed
16
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Dirk Mueller's avatar
Dirk Mueller committed
17
   Boston, MA 02110-1301, USA.
18
*/
19

20
#include "konq_listview.h"
Alexander Neundorf's avatar
   
Alexander Neundorf committed
21
22
#include "konq_textviewwidget.h"
#include "konq_treeviewwidget.h"
23
#include "konq_infolistviewwidget.h"
24
#include "konq_listviewsettings.h"
25

26
27
#include <konqmimedata.h>

28
#include <kaction.h>
29
#include <kapplication.h>
30
#include <kdebug.h>
Michael Brade's avatar
Michael Brade committed
31
#include <kdirlister.h>
Nadeem Hasan's avatar
Nadeem Hasan committed
32
#include <kinputdialog.h>
33
#include <klocale.h>
Marc Mutz's avatar
Marc Mutz committed
34
#include <kpropertiesdialog.h>
35
#include <kstdaction.h>
36
#include <kprotocolinfo.h>
37
#include <klineedit.h>
38
#include <kmimetype.h>
39
40
41

#include <qapplication.h>
#include <qclipboard.h>
42
#include <q3header.h>
43
#include <qregexp.h>
44
45
46
47
48
49

#include <assert.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
David Faure's avatar
David Faure committed
50
#include <kinstance.h>
51

52
KonqListViewFactory::KonqListViewFactory()
53
{
54
55
  s_instance = 0;
  s_defaultViewProps = 0;
56
}
57

58
59
KonqListViewFactory::~KonqListViewFactory()
{
60
61
  delete s_instance;
  delete s_defaultViewProps;
62

63
64
  s_instance = 0;
  s_defaultViewProps = 0;
65
}
66

67
KParts::Part* KonqListViewFactory::createPartObject( QWidget *parentWidget, const char *, QObject *parent, const char *name, const char*, const QStringList &args )
68
69
{
  if( args.count() < 1 )
Laurent Montel's avatar
Laurent Montel committed
70
    kWarning() << "KonqListView: Missing Parameter" << endl;
71

72
73
  KParts::Part *obj = new KonqListView( parentWidget, parent, args.first() );
  obj->setObjectName( name );
74
75
  return obj;
}
76

77
78
79
KInstance *KonqListViewFactory::instance()
{
  if ( !s_instance )
David Faure's avatar
David Faure committed
80
    s_instance = new KInstance( "konqlistview" );
81
82
  return s_instance;
}
83

84
85
86
KonqPropsView *KonqListViewFactory::defaultViewProps()
{
  if ( !s_defaultViewProps )
Alexander Neundorf's avatar
   
Alexander Neundorf committed
87
88
    s_defaultViewProps = new KonqPropsView( instance(),0L );
    //s_defaultViewProps = KonqPropsView::defaultProps( instance() );
89

90
  return s_defaultViewProps;
91
}
92

93
KInstance *KonqListViewFactory::s_instance = 0;
94
KonqPropsView *KonqListViewFactory::s_defaultViewProps = 0;
95

İsmail Dönmez's avatar
   
İsmail Dönmez committed
96
K_EXPORT_COMPONENT_FACTORY( konq_listview, KonqListViewFactory )
97

98
ListViewBrowserExtension::ListViewBrowserExtension( KonqListView *listView )
99
 : KonqDirPartBrowserExtension( listView )
100
{
101
  m_listView = listView;
102
103
}

104
int ListViewBrowserExtension::xOffset()
105
{
Laurent Montel's avatar
Laurent Montel committed
106
  //kDebug(1202) << k_funcinfo << endl;
107
  return m_listView->listViewWidget()->contentsX();
108
109
}

110
int ListViewBrowserExtension::yOffset()
111
{
Laurent Montel's avatar
Laurent Montel committed
112
  //kDebug(1202) << k_funcinfo << endl;
113
  return m_listView->listViewWidget()->contentsY();
114
115
}

116
void ListViewBrowserExtension::updateActions()
117
{
118
  // This code is very related to KonqIconViewWidget::slotSelectionChanged
119
120
  int canCopy = 0;
  int canDel = 0;
121
  int canTrash = 0;
122
  bool bInTrash = false;
123
  const KFileItemList lstItems = m_listView->selectedFileItems();
Pascal Létourneau's avatar
   
Pascal Létourneau committed
124

125
126
127
  KFileItemList::const_iterator kit = lstItems.begin();
  const KFileItemList::const_iterator kend = lstItems.end();
  for (; kit != kend; ++kit )
128
  {
129
    KFileItem* item = *kit;
130
    canCopy++;
Laurent Montel's avatar
Laurent Montel committed
131
    KUrl url = item->url();
132
133
#warning hardcoded protocol: find a better way to determine if a url is a trash url.
    if ( url.protocol() == "trash" )
134
135
136
      bInTrash = true;
    if (  KProtocolInfo::supportsDeleting(  url ) )
      canDel++;
137
138
    if ( !item->localPath().isEmpty() )
      canTrash++;
139
  }
140

141
142
  emit enableAction( "copy", canCopy > 0 );
  emit enableAction( "cut", canDel > 0 );
143
  emit enableAction( "trash", canDel > 0 && !bInTrash && canDel == canTrash );
144
  emit enableAction( "del", canDel > 0 );
145
146
  emit enableAction( "properties", lstItems.count() > 0 && KPropertiesDialog::canDisplay( lstItems ) );
  emit enableAction( "editMimeType", ( lstItems.count() == 1 ) );
147
  emit enableAction( "rename", ( m_listView->listViewWidget()->currentItem() != 0 )&& !bInTrash );
148
}
149

150
void ListViewBrowserExtension::copySelection( bool move )
151
{
152
153
154
155
  QMimeData* mimeData = new QMimeData;
  KonqMimeData::populateMimeData( mimeData, m_listView->listViewWidget()->selectedUrls(false),
                                  m_listView->listViewWidget()->selectedUrls(true), move );
  QApplication::clipboard()->setMimeData( mimeData );
156
}
157

158
void ListViewBrowserExtension::paste()
159
{
David Faure's avatar
David Faure committed
160
161
162
  KonqOperations::doPaste( m_listView->listViewWidget(), m_listView->url() );
}

Laurent Montel's avatar
Laurent Montel committed
163
void ListViewBrowserExtension::pasteTo( const KUrl& url )
David Faure's avatar
David Faure committed
164
165
{
  KonqOperations::doPaste( m_listView->listViewWidget(), url );
166
}
167

168
169
void ListViewBrowserExtension::rename()
{
170
  Q3ListViewItem* item = m_listView->listViewWidget()->currentItem();
171
172
  Q_ASSERT ( item );
  m_listView->listViewWidget()->rename( item, 0 );
173
174
175
176

  // Enhanced rename: Don't highlight the file extension.
  KLineEdit* le = m_listView->listViewWidget()->renameLineEdit();
  if ( le ) {
177
178
179
     const QString txt = le->text();
     QString pattern;
     KMimeType::diagnoseFileName( txt, pattern );
180
     if (!pattern.isEmpty() && pattern.at(0)=='*' && pattern.indexOf('*',1)==-1)
Laurent Montel's avatar
Laurent Montel committed
181
         le->setSelection(0, txt.length()-pattern.trimmed().length()+1);
182
183
     else
     {
184
         int lastDot = txt.lastIndexOf('.');
185
186
187
         if (lastDot > 0)
             le->setSelection(0, lastDot);
     }
188
  }
189
190
}

191
192
void ListViewBrowserExtension::trash()
{
193
194
  KonqOperations::del(m_listView->listViewWidget(),
                      KonqOperations::TRASH,
195
                      m_listView->listViewWidget()->selectedUrls( true ));
196
197
}

198
void ListViewBrowserExtension::reparseConfiguration()
199
{
200
201
  // m_pProps is a problem here (what is local, what is global ?)
  // but settings is easy :
202
  m_listView->listViewWidget()->initConfig();
203
204
}

Alexander Neundorf's avatar
   
Alexander Neundorf committed
205
void ListViewBrowserExtension::setSaveViewPropertiesLocally(bool value)
206
{
207
   m_listView->props()->setSaveViewPropertiesLocally( value );
208
}
Alexander Neundorf's avatar
   
Alexander Neundorf committed
209

210
void ListViewBrowserExtension::setNameFilter( const QString &nameFilter )
Alexander Neundorf's avatar
   
Alexander Neundorf committed
211
{
212
  m_listView->setNameFilter( nameFilter );
213
}
214

215
216
void ListViewBrowserExtension::properties()
{
217
  (void) new KPropertiesDialog( m_listView->selectedFileItems() );
218
219
220
221
}

void ListViewBrowserExtension::editMimeType()
{
222
223
224
  KFileItemList items = m_listView->selectedFileItems();
  assert ( items.count() == 1 );
  KonqOperations::editMimeType( items.first()->mimetype() );
225
226
}

227
228
KonqListView::KonqListView( QWidget *parentWidget, QObject *parent, const QString& mode )
 : KonqDirPart( parent )
229
,m_headerTimer(0)
230
{
231
232
   setInstance( KonqListViewFactory::instance(), false );

233
234
235
236
   // Create a properties instance for this view
   // All the listview view modes inherit the same properties defaults...
   m_pProps = new KonqPropsView( KonqListViewFactory::instance(), KonqListViewFactory::defaultViewProps() );

237
   setBrowserExtension( new ListViewBrowserExtension( this ) );
238

239
240
   QString xmlFile;

Alexander Neundorf's avatar
   
Alexander Neundorf committed
241
242
   if (mode=="TextView")
   {
Laurent Montel's avatar
Laurent Montel committed
243
      kDebug(1202) << "Creating KonqTextViewWidget" << endl;
244
      xmlFile = "konq_textview.rc";
Alexander Neundorf's avatar
   
Alexander Neundorf committed
245
246
247
248
      m_pListView=new KonqTextViewWidget(this, parentWidget);
   }
   else if (mode=="MixedTree")
   {
Laurent Montel's avatar
Laurent Montel committed
249
      kDebug(1202) << "Creating KonqTreeViewWidget" << endl;
250
      xmlFile = "konq_treeview.rc";
Alexander Neundorf's avatar
   
Alexander Neundorf committed
251
252
      m_pListView=new KonqTreeViewWidget(this,parentWidget);
   }
253
254
   else if (mode=="InfoListView")
   {
Laurent Montel's avatar
Laurent Montel committed
255
      kDebug(1202) << "Creating KonqInfoListViewWidget" << endl;
256
      xmlFile = "konq_infolistview.rc";
257
258
      m_pListView=new KonqInfoListViewWidget(this,parentWidget);
   }
Alexander Neundorf's avatar
   
Alexander Neundorf committed
259
260
   else
   {
Laurent Montel's avatar
Laurent Montel committed
261
      kDebug(1202) << "Creating KonqDetailedListViewWidget" << endl;
262
      xmlFile = "konq_detailedlistview.rc";
Alexander Neundorf's avatar
   
Alexander Neundorf committed
263
264
265
      m_pListView = new KonqBaseListViewWidget( this, parentWidget);
   }
   setWidget( m_pListView );
David Faure's avatar
David Faure committed
266
267
   setDirLister( m_pListView->m_dirLister );

268
   m_mimeTypeResolver = new KMimeTypeResolver<KonqBaseListViewItem,KonqListView>(this);
269

270
271
   setXMLFile( xmlFile );

Alexander Neundorf's avatar
   
Alexander Neundorf committed
272
273
   setupActions();

274
   m_pListView->confColumns.resize( 11 );
275
276
277
278
279
280
281
282
283
284
   m_pListView->confColumns[0].setData(I18N_NOOP("MimeType"),"Type",KIO::UDS_MIME_TYPE,m_paShowMimeType);
   m_pListView->confColumns[1].setData(I18N_NOOP("Size"),"Size",KIO::UDS_SIZE,m_paShowSize);
   m_pListView->confColumns[2].setData(I18N_NOOP("Modified"),"Date",KIO::UDS_MODIFICATION_TIME,m_paShowTime);
   m_pListView->confColumns[3].setData(I18N_NOOP("Accessed"),"AccessDate",KIO::UDS_ACCESS_TIME,m_paShowAccessTime);
   m_pListView->confColumns[4].setData(I18N_NOOP("Created"),"CreationDate",KIO::UDS_CREATION_TIME,m_paShowCreateTime);
   m_pListView->confColumns[5].setData(I18N_NOOP("Permissions"),"Access",KIO::UDS_ACCESS,m_paShowPermissions);
   m_pListView->confColumns[6].setData(I18N_NOOP("Owner"),"Owner",KIO::UDS_USER,m_paShowOwner);
   m_pListView->confColumns[7].setData(I18N_NOOP("Group"),"Group",KIO::UDS_GROUP,m_paShowGroup);
   m_pListView->confColumns[8].setData(I18N_NOOP("Link"),"Link",KIO::UDS_LINK_DEST,m_paShowLinkDest);
   m_pListView->confColumns[9].setData(I18N_NOOP("URL"),"URL",KIO::UDS_URL,m_paShowURL);
Alexander Neundorf's avatar
   
Alexander Neundorf committed
285
   // Note: File Type is in fact the mimetype comment. We use UDS_FILE_TYPE but that's not what we show in fact :/
286
   m_pListView->confColumns[10].setData(I18N_NOOP("File Type"),"Type",KIO::UDS_FILE_TYPE,m_paShowType);
Alexander Neundorf's avatar
   
Alexander Neundorf committed
287

288

289
290
   connect( m_pListView, SIGNAL( selectionChanged() ),
            m_extension, SLOT( updateActions() ) );
291
292
293
   connect( m_pListView, SIGNAL( selectionChanged() ),
            this, SLOT( slotSelectionChanged() ) );

294
295
   connect( m_pListView, SIGNAL( currentChanged(QListViewItem*) ),
            m_extension, SLOT( updateActions() ) );
Alexander Neundorf's avatar
   
Alexander Neundorf committed
296
   connect(m_pListView->header(),SIGNAL(indexChange(int,int,int)),this,SLOT(headerDragged(int,int,int)));
Alexander Neundorf's avatar
   
Alexander Neundorf committed
297
   connect(m_pListView->header(),SIGNAL(clicked(int)),this,SLOT(slotHeaderClicked(int)));
298
   connect(m_pListView->header(),SIGNAL(sizeChange(int,int,int)),SLOT(slotHeaderSizeChanged()));
299
300
301
302

   // signals from konqdirpart (for BC reasons)
   connect( this, SIGNAL( findOpened( KonqDirPart * ) ), SLOT( slotKFindOpened() ) );
   connect( this, SIGNAL( findClosed( KonqDirPart * ) ), SLOT( slotKFindClosed() ) );
303
304

   loadPlugins( this, this, instance() );
305
306
}

307
KonqListView::~KonqListView()
308
{
309
  delete m_mimeTypeResolver;
310
311
  delete m_pProps;
}
312

Alexander Neundorf's avatar
   
Alexander Neundorf committed
313
314
315
316
317
void KonqListView::guiActivateEvent( KParts::GUIActivateEvent *event )
{
   KonqDirPart::guiActivateEvent(event );
   //ReadOnlyPart::guiActivateEvent(event );
   ((ListViewBrowserExtension*)m_extension)->updateActions();
Dirk Mueller's avatar
Dirk Mueller committed
318
}
Alexander Neundorf's avatar
   
Alexander Neundorf committed
319

Laurent Montel's avatar
Laurent Montel committed
320
bool KonqListView::doOpenURL( const KUrl &url )
321
{
Laurent Montel's avatar
Laurent Montel committed
322
  KUrl u( url );
323
  const QString prettyURL = url.pathOrURL();
324
  emit setWindowCaption( prettyURL );
325
  return m_pListView->openURL( url );
326
}
327

328
bool KonqListView::doCloseURL()
329
{
330
  m_pListView->stop();
331
  m_mimeTypeResolver->m_lstPendingMimeIconItems.clear();
David Faure's avatar
David Faure committed
332
  return true;
333
334
}

335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
void KonqListView::listingComplete()
{
  m_mimeTypeResolver->start( /*10*/ 0 );
}

void KonqListView::determineIcon( KonqBaseListViewItem * item )
{
  //int oldSerial = item->pixmap(0)->serialNumber();

  (void) item->item()->determineMimeType();

  //QPixmap newIcon = item->item()->pixmap( m_parent->iconSize(),
  //                                        item->state() );
  //if ( oldSerial != newIcon.serialNumber() )
  //  item->setPixmap( 0, newIcon );

  // We also have columns to update, not only the icon
  item->updateContents();
}

355
356
void KonqListView::saveState( QDataStream &stream )
{
Laurent Montel's avatar
Laurent Montel committed
357
    //kDebug(1202) << k_funcinfo << endl;
358
359
360
361
362
363
    KonqDirPart::saveState( stream );
    m_pListView->saveState( stream );
}

void KonqListView::restoreState( QDataStream &stream )
{
Laurent Montel's avatar
Laurent Montel committed
364
    //kDebug(1202) << k_funcinfo << endl;
365
366
367
368
    KonqDirPart::restoreState( stream );
    m_pListView->restoreState( stream );
}

Laurent Montel's avatar
Laurent Montel committed
369
void KonqListView::disableIcons( const KUrl::List &lst )
370
371
372
373
{
    m_pListView->disableIcons( lst );
}

374
void KonqListView::slotSelect()
375
{
Nadeem Hasan's avatar
Nadeem Hasan committed
376
   bool ok;
Laurent Montel's avatar
Laurent Montel committed
377
   QString pattern = KInputDialog::getText( QString(),
Nadeem Hasan's avatar
Nadeem Hasan committed
378
379
      i18n( "Select files:" ), "*", &ok, m_pListView );
   if ( !ok )
Alexander Neundorf's avatar
   
Alexander Neundorf committed
380
      return;
Alexander Neundorf's avatar
   
Alexander Neundorf committed
381

Thorsten Roeder's avatar
Thorsten Roeder committed
382
   QRegExp re( pattern, Qt::CaseSensitive, QRegExp::Wildcard );
Alexander Neundorf's avatar
   
Alexander Neundorf committed
383

Alexander Neundorf's avatar
   
Alexander Neundorf committed
384
   m_pListView->blockSignals( true );
Alexander Neundorf's avatar
   
Alexander Neundorf committed
385

Alexander Neundorf's avatar
   
Alexander Neundorf committed
386
387
388
   for (KonqBaseListViewWidget::iterator it = m_pListView->begin(); it != m_pListView->end(); it++ )
   {
      if ((m_pListView->automaticSelection()) && (it->isSelected()))
Alexander Neundorf's avatar
   
Alexander Neundorf committed
389
      {
Allen Winter's avatar
Allen Winter committed
390
         it->setSelected(false);
Alexander Neundorf's avatar
   
Alexander Neundorf committed
391
392
393
394
         //the following line is to prevent that more than one item were selected
         //and now get deselected and automaticSelection() was true, this shouldn't happen
         //but who knows, aleXXX
         m_pListView->deactivateAutomaticSelection();
Alexander Neundorf's avatar
   
Alexander Neundorf committed
395
      };
396
      if ( re.exactMatch( it->text(0) ) )
Allen Winter's avatar
Allen Winter committed
397
         it->setSelected( true );
Alexander Neundorf's avatar
   
Alexander Neundorf committed
398
399
   };
   m_pListView->blockSignals( false );
Alexander Neundorf's avatar
   
Alexander Neundorf committed
400
   m_pListView->deactivateAutomaticSelection();
Alexander Neundorf's avatar
   
Alexander Neundorf committed
401
   emit m_pListView->selectionChanged();
Alexander Neundorf's avatar
   
Alexander Neundorf committed
402
   m_pListView->viewport()->update();
403
404
405
406
}

void KonqListView::slotUnselect()
{
Nadeem Hasan's avatar
Nadeem Hasan committed
407
   bool ok;
Laurent Montel's avatar
Laurent Montel committed
408
   QString pattern = KInputDialog::getText( QString(),
Nadeem Hasan's avatar
Nadeem Hasan committed
409
410
      i18n( "Unselect files:" ), "*", &ok, m_pListView );
   if ( !ok )
Alexander Neundorf's avatar
   
Alexander Neundorf committed
411
      return;
Alexander Neundorf's avatar
   
Alexander Neundorf committed
412

Thorsten Roeder's avatar
Thorsten Roeder committed
413
   QRegExp re( pattern, Qt::CaseSensitive, QRegExp::Wildcard );
Alexander Neundorf's avatar
   
Alexander Neundorf committed
414

Allen Winter's avatar
Allen Winter committed
415
   m_pListView->blockSignals(true);
Alexander Neundorf's avatar
   
Alexander Neundorf committed
416

Alexander Neundorf's avatar
   
Alexander Neundorf committed
417
   for (KonqBaseListViewWidget::iterator it = m_pListView->begin(); it != m_pListView->end(); it++ )
418
      if ( re.exactMatch( it->text(0) ) )
Allen Winter's avatar
Allen Winter committed
419
         it->setSelected(false);
Alexander Neundorf's avatar
   
Alexander Neundorf committed
420

Allen Winter's avatar
Allen Winter committed
421
   m_pListView->blockSignals(false);
Alexander Neundorf's avatar
   
Alexander Neundorf committed
422
   m_pListView->deactivateAutomaticSelection();
Alexander Neundorf's avatar
   
Alexander Neundorf committed
423
   emit m_pListView->selectionChanged();
Alexander Neundorf's avatar
   
Alexander Neundorf committed
424
   m_pListView->viewport()->update();
425
426
427
428
}

void KonqListView::slotSelectAll()
{
Allen Winter's avatar
Allen Winter committed
429
   m_pListView->selectAll(true);
Alexander Neundorf's avatar
   
Alexander Neundorf committed
430
   m_pListView->deactivateAutomaticSelection();
Alexander Neundorf's avatar
   
Alexander Neundorf committed
431
   emit m_pListView->selectionChanged();
432
433
434
435
}

void KonqListView::slotUnselectAll()
{
Allen Winter's avatar
Allen Winter committed
436
    m_pListView->selectAll(false);
Alexander Neundorf's avatar
   
Alexander Neundorf committed
437
   m_pListView->deactivateAutomaticSelection();
Alexander Neundorf's avatar
   
Alexander Neundorf committed
438
    emit m_pListView->selectionChanged();
439
440
}

Alexander Neundorf's avatar
   
Alexander Neundorf committed
441

442
443
void KonqListView::slotInvertSelection()
{
Alexander Neundorf's avatar
   
Alexander Neundorf committed
444
445
446
   if ((m_pListView->automaticSelection())
       && (m_pListView->currentItem()!=0)
       && (m_pListView->currentItem()->isSelected()))
Allen Winter's avatar
Allen Winter committed
447
      m_pListView->currentItem()->setSelected(false);
Alexander Neundorf's avatar
   
Alexander Neundorf committed
448
449
450

   m_pListView->invertSelection();
    m_pListView->deactivateAutomaticSelection();
Alexander Neundorf's avatar
   
Alexander Neundorf committed
451
    emit m_pListView->selectionChanged();
Alexander Neundorf's avatar
   
Alexander Neundorf committed
452
    m_pListView->viewport()->update();
453
454
}

455
void KonqListView::newIconSize( int size )
456
{
457
458
    KonqDirPart::newIconSize( size );
    m_pListView->updateListContents();
459
460
}

461
void KonqListView::slotShowDot()
462
{
463
464
   m_pProps->setShowingDotFiles( m_paShowDot->isChecked() );
   m_pListView->m_dirLister->setShowingDotFiles( m_pProps->isShowingDotFiles() );
465
   m_pListView->m_dirLister->emitChanges();
466
}
467

468
469
void KonqListView::slotCaseInsensitive()
{
470
   m_pProps->setCaseInsensitiveSort( m_paCaseInsensitive->isChecked() );
471
472
473
   m_pListView->sort();
}

474
void KonqListView::slotColumnToggled()
Alexander Neundorf's avatar
   
Alexander Neundorf committed
475
{
Laurent Montel's avatar
Laurent Montel committed
476
   kDebug(1202) << "::slotColumnToggled" << endl;
David Faure's avatar
David Faure committed
477
   for (uint i=0; i<m_pListView->NumberOfAtoms; i++)
Alexander Neundorf's avatar
   
Alexander Neundorf committed
478
   {
479
480
      m_pListView->confColumns[i].displayThisOne=!m_pListView->confColumns[i].toggleThisOne
        || (m_pListView->confColumns[i].toggleThisOne->isChecked()&&m_pListView->confColumns[i].toggleThisOne->isEnabled());
Alexander Neundorf's avatar
   
Alexander Neundorf committed
481
      //this column has been enabled, the columns after it slide one column back
Alexander Neundorf's avatar
   
Alexander Neundorf committed
482
      if ((m_pListView->confColumns[i].displayThisOne) && (m_pListView->confColumns[i].displayInColumn==-1))
Alexander Neundorf's avatar
   
Alexander Neundorf committed
483
484
      {
         int maxColumn(0);
David Faure's avatar
David Faure committed
485
         for (uint j=0; j<m_pListView->NumberOfAtoms; j++)
Alexander Neundorf's avatar
   
Alexander Neundorf committed
486
487
488
            if ((m_pListView->confColumns[j].displayInColumn>maxColumn) && (m_pListView->confColumns[j].displayThisOne))
               maxColumn=m_pListView->confColumns[j].displayInColumn;
         m_pListView->confColumns[i].displayInColumn=maxColumn+1;
489
      }
Alexander Neundorf's avatar
   
Alexander Neundorf committed
490
      //this column has been disabled, the columns after it slide one column
Alexander Neundorf's avatar
   
Alexander Neundorf committed
491
      if ((!m_pListView->confColumns[i].displayThisOne) && (m_pListView->confColumns[i].displayInColumn!=-1))
Alexander Neundorf's avatar
   
Alexander Neundorf committed
492
      {
David Faure's avatar
David Faure committed
493
         for (uint j=0; j<m_pListView->NumberOfAtoms; j++)
Alexander Neundorf's avatar
   
Alexander Neundorf committed
494
495
496
            if (m_pListView->confColumns[j].displayInColumn>m_pListView->confColumns[i].displayInColumn)
               m_pListView->confColumns[j].displayInColumn--;
         m_pListView->confColumns[i].displayInColumn=-1;
497
498
      }
   }
Alexander Neundorf's avatar
   
Alexander Neundorf committed
499

Alexander Neundorf's avatar
   
Alexander Neundorf committed
500
501
502
   //create the new list contents
   m_pListView->createColumns();
   m_pListView->updateListContents();
Alexander Neundorf's avatar
   
Alexander Neundorf committed
503

Alexander Neundorf's avatar
   
Alexander Neundorf committed
504
505
   //save the config
   QStringList lstColumns;
Alexander Neundorf's avatar
   
Alexander Neundorf committed
506
   int currentColumn(m_pListView->m_filenameColumn+1);
David Faure's avatar
David Faure committed
507
   for (int i=0; i<(int)m_pListView->NumberOfAtoms; i++)
Alexander Neundorf's avatar
   
Alexander Neundorf committed
508
   {
Laurent Montel's avatar
Laurent Montel committed
509
      kDebug(1202)<<"checking: -"<<m_pListView->confColumns[i].name<<"-"<<endl;
Alexander Neundorf's avatar
   
Alexander Neundorf committed
510
      if ((m_pListView->confColumns[i].displayThisOne) && (currentColumn==m_pListView->confColumns[i].displayInColumn))
Alexander Neundorf's avatar
   
Alexander Neundorf committed
511
      {
Alexander Neundorf's avatar
   
Alexander Neundorf committed
512
          lstColumns.append(m_pListView->confColumns[i].name);
Laurent Montel's avatar
Laurent Montel committed
513
          kDebug(1202)<<" adding"<<endl;
Alexander Neundorf's avatar
   
Alexander Neundorf committed
514
515
          currentColumn++;
          i=-1;
516
517
      }
   }
518
519
520
521
   KonqListViewSettings config( m_pListView->url().protocol() );
   config.readConfig();
   config.setColumns( lstColumns );
   config.writeConfig();
522
523

   // Update column sizes
524
   slotHeaderSizeChanged();
525
}
Alexander Neundorf's avatar
   
Alexander Neundorf committed
526

Alexander Neundorf's avatar
   
Alexander Neundorf committed
527
528
void KonqListView::slotHeaderClicked(int sec)
{
Laurent Montel's avatar
Laurent Montel committed
529
   kDebug(1202)<<"section: "<<sec<<" clicked"<<endl;
Alexander Neundorf's avatar
   
Alexander Neundorf committed
530
   int clickedColumn(-1);
David Faure's avatar
David Faure committed
531
   for (uint i=0; i<m_pListView->NumberOfAtoms; i++)
Alexander Neundorf's avatar
   
Alexander Neundorf committed
532
      if (m_pListView->confColumns[i].displayInColumn==sec) clickedColumn=i;
Laurent Montel's avatar
Laurent Montel committed
533
   kDebug(1202)<<"atom index "<<clickedColumn<<endl;
Alexander Neundorf's avatar
   
Alexander Neundorf committed
534
535
536
537
538
539
   QString nameOfSortColumn;
   //we clicked the file name column
   if (clickedColumn==-1)
      nameOfSortColumn="FileName";
   else
      nameOfSortColumn=m_pListView->confColumns[clickedColumn].desktopFileName;
540

Alexander Neundorf's avatar
   
Alexander Neundorf committed
541
   if (nameOfSortColumn!=m_pListView->sortedByColumn)
Alexander Neundorf's avatar
   
Alexander Neundorf committed
542
   {
Alexander Neundorf's avatar
   
Alexander Neundorf committed
543
      m_pListView->sortedByColumn=nameOfSortColumn;
Allen Winter's avatar
Allen Winter committed
544
      m_pListView->setAscending(true);
Alexander Neundorf's avatar
   
Alexander Neundorf committed
545
546
   }
   else
547
      m_pListView->setAscending(!m_pListView->ascending());
548

549
550
551
552
553
   KonqListViewSettings config( m_pListView->url().protocol() );
   config.readConfig();
   config.setSortBy( nameOfSortColumn );
   config.setSortOrder( m_pListView->ascending() );
   config.writeConfig();
Dirk Mueller's avatar
Dirk Mueller committed
554
}
Alexander Neundorf's avatar
   
Alexander Neundorf committed
555

Alexander Neundorf's avatar
   
Alexander Neundorf committed
556
557
void KonqListView::headerDragged(int sec, int from, int to)
{
Laurent Montel's avatar
Laurent Montel committed
558
   kDebug(1202)<<"section: "<<sec<<" fromIndex: "<<from<<" toIndex "<<to<<endl;
Alexander Neundorf's avatar
   
Alexander Neundorf committed
559
560
561
   //at this point the columns aren't moved yet, so I let the listview
   //rearrange the stuff and use a single shot timer
   QTimer::singleShot(200,this,SLOT(slotSaveAfterHeaderDrag()));
562
}
Alexander Neundorf's avatar
   
Alexander Neundorf committed
563

564
565
566
567
568
569
const KFileItem * KonqListView::currentItem()
{
   if (m_pListView==0 || m_pListView->currentItem()==0)
      return 0L;
   return static_cast<KonqListViewItem *>(m_pListView->currentItem())->item();
}
Alexander Neundorf's avatar
   
Alexander Neundorf committed
570

Alexander Neundorf's avatar
   
Alexander Neundorf committed
571
572
573
574
void KonqListView::slotSaveAfterHeaderDrag()
{
   QStringList lstColumns;

575
   for ( int i=0; i < m_pListView->columns(); i++ )
Alexander Neundorf's avatar
   
Alexander Neundorf committed
576
   {
577
      int section = m_pListView->header()->mapToSection( i );
David Faure's avatar
David Faure committed
578

579
      // look for section
David Faure's avatar
David Faure committed
580
      for ( uint j=0; j < m_pListView->NumberOfAtoms; j++ )
Alexander Neundorf's avatar
   
Alexander Neundorf committed
581
      {
582
         if ( m_pListView->confColumns[j].displayInColumn == section )
Alexander Neundorf's avatar
   
Alexander Neundorf committed
583
         {
584
585
            lstColumns.append( m_pListView->confColumns[j].name );
            break;
586
587
588
         }
      }
   }
589
590
591
592
   KonqListViewSettings config( m_pListView->url().protocol() );
   config.readConfig();
   config.setColumns( lstColumns );
   config.writeConfig();
593
594

   // Update column sizes
595
596
597
598
599
   slotHeaderSizeChanged();
}

void KonqListView::slotSaveColumnWidths()
{
Laurent Montel's avatar
Laurent Montel committed
600
   QList<int> lstColumnWidths;
David Faure's avatar
David Faure committed
601

602
603
604
   for ( int i=0; i < m_pListView->columns(); i++ )
   {
      int section = m_pListView->header()->mapToSection( i );
David Faure's avatar
David Faure committed
605

606
      // look for section
David Faure's avatar
David Faure committed
607
      for ( uint j=0; j < m_pListView->NumberOfAtoms; j++ )
608
609
610
611
612
613
614
615
616
617
      {
         // Save size only if the column is found
         if ( m_pListView->confColumns[j].displayInColumn == section )
         {
            m_pListView->confColumns[j].width = m_pListView->columnWidth(section);
            lstColumnWidths.append( m_pListView->confColumns[j].width );
            break;
         }
      }
   }
618
619
620
   KonqListViewSettings config( m_pListView->url().protocol() );
   config.readConfig();
   config.setColumnWidths( lstColumnWidths );
David Faure's avatar
David Faure committed
621

622
   // size of current filename column
623
624
   config.setFileNameColumnWidth( m_pListView->columnWidth(0) );
   config.writeConfig();
625
626
627
628
629
630
631
632
633
634
635
636
}

void KonqListView::slotHeaderSizeChanged()
{
   if ( !m_headerTimer )
   {
      m_headerTimer = new QTimer( this );
      connect( m_headerTimer, SIGNAL( timeout() ), this, SLOT( slotSaveColumnWidths() ) );
   }
   else
      m_headerTimer->stop();

637
638
   m_headerTimer->setSingleShot( true );
   m_headerTimer->start( 250 );
639
}
Alexander Neundorf's avatar
   
Alexander Neundorf committed
640

641
642
643
644
645
646
647
648
649
650
651
void KonqListView::slotKFindOpened()
{
    if ( m_pListView->m_dirLister )
        m_pListView->m_dirLister->setAutoUpdate( false );
}

void KonqListView::slotKFindClosed()
{
    if ( m_pListView->m_dirLister )
        m_pListView->m_dirLister->setAutoUpdate( true );
}
Alexander Neundorf's avatar
   
Alexander Neundorf committed
652

653
654
void KonqListView::setupActions()
{
Alexander Neundorf's avatar
   
Alexander Neundorf committed
655
   m_paShowTime=new KToggleAction(i18n("Show &Modification Time"), 0,this, SLOT(slotColumnToggled()), actionCollection(), "show_time" );
Stephan Binner's avatar
Stephan Binner committed
656
   m_paShowTime->setCheckedState(i18n("Hide &Modification Time"));
Alexander Neundorf's avatar
   
Alexander Neundorf committed
657
   m_paShowType=new KToggleAction(i18n("Show &File Type"), 0, this, SLOT(slotColumnToggled()),actionCollection(), "show_type" );
Stephan Binner's avatar
Stephan Binner committed
658
   m_paShowType->setCheckedState(i18n("Hide &File Type"));
Alexander Neundorf's avatar
   
Alexander Neundorf committed
659
   m_paShowMimeType=new KToggleAction(i18n("Show MimeType"), 0, this, SLOT(slotColumnToggled()),actionCollection(), "show_mimetype" );
Stephan Binner's avatar
Stephan Binner committed
660
   m_paShowMimeType->setCheckedState(i18n("Hide MimeType"));
Alexander Neundorf's avatar
   
Alexander Neundorf committed
661
   m_paShowAccessTime=new KToggleAction(i18n("Show &Access Time"), 0, this, SLOT(slotColumnToggled()),actionCollection(), "show_access_time" );
Stephan Binner's avatar
Stephan Binner committed
662
   m_paShowAccessTime->setCheckedState(i18n("Hide &Access Time"));
Alexander Neundorf's avatar
   
Alexander Neundorf committed
663
   m_paShowCreateTime=new KToggleAction(i18n("Show &Creation Time"), 0, this, SLOT(slotColumnToggled()),actionCollection(), "show_creation_time" );
Stephan Binner's avatar
Stephan Binner committed
664
   m_paShowCreateTime->setCheckedState(i18n("Hide &Creation Time"));
Alexander Neundorf's avatar
   
Alexander Neundorf committed
665
   m_paShowLinkDest=new KToggleAction(i18n("Show &Link Destination"), 0, this, SLOT(slotColumnToggled()),actionCollection(), "show_link_dest" );
Stephan Binner's avatar
Stephan Binner committed
666
   m_paShowLinkDest->setCheckedState(i18n("Hide &Link Destination"));
Alexander Neundorf's avatar
   
Alexander Neundorf committed
667
   m_paShowSize=new KToggleAction(i18n("Show Filesize"), 0, this, SLOT(slotColumnToggled()),actionCollection(), "show_size" );
Stephan Binner's avatar
Stephan Binner committed
668
   m_paShowSize->setCheckedState(i18n("Hide Filesize"));
Alexander Neundorf's avatar
   
Alexander Neundorf committed
669
   m_paShowOwner=new KToggleAction(i18n("Show Owner"), 0, this, SLOT(slotColumnToggled()),actionCollection(), "show_owner" );
Stephan Binner's avatar
Stephan Binner committed
670
   m_paShowOwner->setCheckedState(i18n("Hide Owner"));
Alexander Neundorf's avatar
   
Alexander Neundorf committed
671
   m_paShowGroup=new KToggleAction(i18n("Show Group"), 0, this, SLOT(slotColumnToggled()),actionCollection(), "show_group" );
Stephan Binner's avatar
Stephan Binner committed
672
   m_paShowGroup->setCheckedState(i18n("Hide Group"));
Alexander Neundorf's avatar
   
Alexander Neundorf committed
673
   m_paShowPermissions=new KToggleAction(i18n("Show Permissions"), 0, this, SLOT(slotColumnToggled()),actionCollection(), "show_permissions" );
Stephan Binner's avatar
Stephan Binner committed
674
   m_paShowPermissions->setCheckedState(i18n("Hide Permissions"));
Alexander Neundorf's avatar
   
Alexander Neundorf committed
675
   m_paShowURL=new KToggleAction(i18n("Show URL"), 0, this, SLOT(slotColumnToggled()),actionCollection(), "show_url" );
Alexander Neundorf's avatar
   
Alexander Neundorf committed
676

Stephan Kulow's avatar
Stephan Kulow committed
677
678
679
680
681
682
   m_paSelect = new KAction( i18n( "Se&lect..." ), actionCollection(), "select" );
   connect(m_paSelect, SIGNAL(triggered(bool) ), SLOT( slotSelect() ));
   m_paSelect->setShortcut(Qt::CTRL+Qt::Key_Plus);
  m_paUnselect = new KAction( i18n( "Unselect..." ), actionCollection(), "unselect" );
  connect(m_paUnselect, SIGNAL(triggered(bool) ), SLOT( slotUnselect() ));
  m_paUnselect->setShortcut(Qt::CTRL+Qt::Key_Minus);
683
  m_paSelectAll = KStdAction::selectAll( this, SLOT( slotSelectAll() ), actionCollection(), "selectall" );
Stephan Kulow's avatar
Stephan Kulow committed
684
685
686
687
688
689
  m_paUnselectAll = new KAction( i18n( "Unselect All" ), actionCollection(), "unselectall" );
  connect(m_paUnselectAll, SIGNAL(triggered(bool) ), SLOT( slotUnselectAll() ));
  m_paUnselectAll->setShortcut(Qt::CTRL+Qt::Key_U);
  m_paInvertSelection = new KAction( i18n( "&Invert Selection" ), actionCollection(), "invertselection" );
  connect(m_paInvertSelection, SIGNAL(triggered(bool) ), SLOT( slotInvertSelection() ));
  m_paInvertSelection->setShortcut(Qt::CTRL+Qt::Key_Asterisk);
690

691
  m_paShowDot = new KToggleAction( i18n( "Show &Hidden Files" ), 0, this, SLOT( slotShowDot() ), actionCollection(), "show_dot" );
Stephan Binner's avatar
Stephan Binner committed
692
//  m_paShowDot->setCheckedState(i18n("Hide &Hidden Files"));
693
  m_paCaseInsensitive = new KToggleAction(i18n("Case Insensitive Sort"), 0, this, SLOT(slotCaseInsensitive()),actionCollection(), "sort_caseinsensitive" );
694

695
  newIconSize( K3Icon::SizeSmall /* default size */ );
696
697
}

698
699
700
701
702
void KonqListView::slotSelectionChanged()
{
  bool itemSelected = selectedFileItems().count()>0;
  m_paUnselect->setEnabled( itemSelected );
  m_paUnselectAll->setEnabled( itemSelected );
703
//  m_paInvertSelection->setEnabled( itemSelected );
704
705
}

706
#include "konq_listview.moc"
707

708