summaryrefslogtreecommitdiffstats
path: root/quanta/treeviews/projecttreeview.cpp
blob: 0b28e2465a25a92c987fceca5a5b542823217b08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
/***************************************************************************
                          projecttreeview.cpp  -  description
                             -------------------
    begin                : Tue Mar 14 2000
    copyright            : (C) 2000 by Yacovlev Alexander & Dmitry Poplavsky <pdima@mail.univ.kiev.ua>
                           (C) 2001-2004 Andras Mantia <amantia@kde.org>
 ***************************************************************************/

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

// QT includes
#include <tqpainter.h>
#include <tqlabel.h>
#include <tqlineedit.h>
#include <tqdict.h>

// KDE includes
#include <klocale.h>
#include <kiconloader.h>
#include <kinputdialog.h>
#include <kmessagebox.h>
#include <kdebug.h>
#include <kpopupmenu.h>
#include <kpropertiesdialog.h>
#include <ktempfile.h>
#include <kapplication.h>
#include <kstringhandler.h>

// app includes
#include "projecttreeview.h"
#include "projectlist.h"
#include "projecturl.h"
#include "quantacommon.h"
#include "qextfileinfo.h"
#include "resource.h"
#include "fileinfodlg.h"
#ifdef ENABLE_CVSSERVICE
#include "cvsservice.h"
#endif

//ProjectTreeViewItem implementation
ProjectTreeViewItem::ProjectTreeViewItem( KFileTreeViewItem *parent, KFileItem* item, KFileTreeBranch *brnch )
: BaseTreeViewItem( parent, item, brnch)
{
}

void ProjectTreeViewItem::paintCell(TQPainter *p, const TQColorGroup &cg,
                                  int column, int width, int align)
{
    TQFont f = p->font();
    if (ProjectTreeView::ref()->isDocumentFolder(url()))
    {
       f.setItalic(true);
       if (text(1).isEmpty())
         setText(1, i18n("Document Base Folder"));
    } else
    {
      if (text(1) == i18n("Document Base Folder"))
          setText(1, "");
    }
    p->setFont(f);
    BaseTreeViewItem::paintCell( p, cg, column, width, align );
}

//ProjectTreeBranch implementation
ProjectTreeBranch::ProjectTreeBranch(KFileTreeView *parent, const KURL& url,
                                     const TQString& name, const TQPixmap& pix,
                                     bool showHidden,
                                     KFileTreeViewItem *branchRoot)
    : BaseTreeBranch(parent, url, name, pix, showHidden, branchRoot)
{
}

KFileTreeViewItem* ProjectTreeBranch::createTreeViewItem(KFileTreeViewItem *parent,
                                                         KFileItem *fileItem )
{
  BaseTreeViewItem  *tvi = 0;
  if( parent && fileItem )
  {
    tvi = new ProjectTreeViewItem( parent, fileItem, this );
    if (tvi)
    {
      // we assume there are childs
      tvi->setExpandable(tvi->isDir());
      if (urlList) {
        tvi->setVisible(urlList->contains(fileItem->url()));  // only listelements
      }
    }
  }
  else
    kdDebug(24000) << "ProjectTreeBranch::createTreeViewItem: Have no parent" << endl;
  return tvi;
}

//ProjectTreeView implementation
ProjectTreeView::ProjectTreeView(TQWidget *parent, const char *name )
  : BaseTreeView(parent,name), m_projectFiles(0)
{
  //setSelectionModeExt(KListView::Extended);
  setRootIsDecorated(false);
  addColumn(i18n("Project Files"), -1);
  addColumn(i18n("Description"), -1);
  setDragEnabled(true);
  setAcceptDrops(true);
  setItemsRenameable(true);
  setRenameable(0, false);
  setRenameable(1, true);

  m_projectBaseURL = KURL();
  newBranch(m_projectBaseURL);  // create an empty project branch
  m_projectDir->root()->setEnabled(false);

  m_uploadStatusMenu = new KPopupMenu(this);
  m_alwaysUploadId = m_uploadStatusMenu->insertItem(i18n("&When Modified"), this, TQT_SLOT(slotAlwaysUpload()));
  m_neverUploadId = m_uploadStatusMenu->insertItem(i18n("&Never"), this, TQT_SLOT(slotNeverUpload()));
  m_confirmUploadId = m_uploadStatusMenu->insertItem(i18n("&Confirm"), this, TQT_SLOT(slotConfirmUpload()));
  connect(m_uploadStatusMenu, TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(slotUploadMenuAboutToShow()));

  m_fileMenu = new KPopupMenu(this);

  m_fileMenu->insertItem(SmallIcon("fileopen"), i18n("&Open"), this, TQT_SLOT(slotOpen()));
  m_openInQuantaId = m_fileMenu->insertItem(i18n("Load Toolbar"), this, TQT_SLOT(slotLoadToolbar()));
  m_fileMenu->insertItem(i18n("Insert &Tag"), this, TQT_SLOT(slotInsertTag()));
  m_menuClose = m_fileMenu->insertItem(SmallIcon("fileclose"), i18n("Clos&e"), this, TQT_SLOT(slotClose()));
  m_fileMenu->insertSeparator();
  m_fileMenu->insertItem(SmallIcon("up"), i18n("&Upload File..."), this, TQT_SLOT(slotUploadSingleURL()));
  m_fileMenu->insertItem(SmallIcon("up"), i18n("&Quick File Upload"), this, TQT_SLOT(slotQuickUploadURL()));
  m_fileMenu->insertItem(i18n("Re&name"), this, TQT_SLOT(slotStartRename()));
  m_fileMenu->insertItem( i18n("&Remove From Project"), this, TQT_SLOT(slotRemoveFromProject(int)));
  m_fileMenu->insertItem(SmallIcon("editdelete"), i18n("&Delete"), this, TQT_SLOT(slotDelete()));
  m_fileMenu->insertSeparator();
  m_fileMenu->insertItem(i18n("Upload &Status"), m_uploadStatusMenu);
  m_fileMenu->insertItem(SmallIcon("info"), i18n("&Properties"), this, TQT_SLOT(slotProperties()));

  KPopupMenu *createNewMenu = new KPopupMenu(this);
  createNewMenu->insertItem(SmallIcon("folder_new"), i18n("F&older..."), this, TQT_SLOT(slotCreateFolder()));
  createNewMenu->insertItem(SmallIcon("document"), i18n("&File..."), this, TQT_SLOT(slotCreateFile()));

  m_folderMenu = new KPopupMenu(this);

  m_folderMenu->insertItem(SmallIconSet("filenew"), i18n("&Create New"), createNewMenu);
  m_folderMenu->insertSeparator();
  m_folderMenu->insertItem(SmallIcon("up"), i18n("&Upload Folder..."), this, TQT_SLOT(slotUploadSingleURL()));
  m_folderMenu->insertItem(SmallIcon("up"), i18n("&Quick Folder Upload"), this, TQT_SLOT(slotQuickUploadURL()));
  m_folderMenu->insertItem(i18n("Create Site &Template..."), this, TQT_SLOT(slotCreateSiteTemplate()));
  m_folderMenu->insertItem(i18n("Re&name"), this, TQT_SLOT(slotStartRename()));
  m_folderMenu->insertItem(i18n("&Remove From Project"), this, TQT_SLOT(slotRemoveFromProject(int)));
  m_folderMenu->insertItem(SmallIcon("editdelete"), i18n("&Delete"), this, TQT_SLOT(slotDelete()));
  m_folderMenu->insertSeparator();
  m_setDocumentRootId = m_folderMenu->insertItem(i18n("Document-&Base Folder"), this, TQT_SLOT(slotChangeDocumentFolderStatus()));
  m_folderMenu->insertItem(i18n("Upload &Status"), m_uploadStatusMenu);
  m_folderMenu->insertItem(SmallIcon("info"), i18n("&Properties"), this, TQT_SLOT(slotProperties()));

  m_projectMenu = new KPopupMenu(this);
  m_projectMenu->insertItem(SmallIconSet("filenew"), i18n("&Create New"), createNewMenu);
  m_projectMenu->insertSeparator();
  m_projectMenu->insertItem(SmallIcon("up"), i18n("&Upload Project..."), this, TQT_SLOT(slotUploadProject()));
  m_projectMenu->insertItem(SmallIcon("reload"), i18n("Re&scan Project Folder..."), this, TQT_SLOT(slotRescan()));
  m_projectMenu->insertItem(SmallIcon("configure"), i18n("Project &Properties"), this, TQT_SLOT(slotOptions()));
  m_projectMenu->insertItem(SmallIcon("revert"), i18n("&Reload"), this, TQT_SLOT(slotReload()));
  m_projectMenu->insertSeparator();
  m_projectMenu->insertItem(i18n("Upload &Status"), m_uploadStatusMenu);


  connect(this, TQT_SIGNAL(contextMenu(KListView*, TQListViewItem*, const TQPoint&)),
          this, TQT_SLOT(slotMenu(KListView*, TQListViewItem*, const TQPoint&)));

  connect(this, TQT_SIGNAL(open(TQListViewItem *)),
          this, TQT_SLOT(slotSelectFile(TQListViewItem *)));

  restoreLayout(kapp->config(), className());
  // the restored size of the first column might be too large for the current content
  // we set it to 10 and the listview will adjust it to the size of the largest entry
  setColumnWidth(0, 10);
}

ProjectTreeView::~ProjectTreeView(){
}


KFileTreeBranch* ProjectTreeView::newBranch(const KURL& url)
{
  TQString m_projectNameStr = m_projectName+" ";
  if (m_projectName)
  {
    if (url.protocol() == "file")
    {
      m_projectNameStr += i18n("[local disk]");
    } else
    {
      m_projectNameStr += "[" + url.protocol() + "://" + url.user() + "@" + url.host() + "]";
    }
    m_projectDir =  new ProjectTreeBranch( this, url, m_projectNameStr, SmallIcon("ptab"), true);
    m_projectDir->root()->setText(1, url.prettyURL());
    setDragEnabled(true);
    setRootIsDecorated(true);
  } else {
    m_projectDir =  new ProjectTreeBranch( this, url, i18n("No Project"), SmallIcon("ptab"), true);
    m_projectDir->root()->setText(1, "");
    setDragEnabled(false);
    setRootIsDecorated(false);
  }

  connect(m_projectDir, TQT_SIGNAL(populateFinished(KFileTreeViewItem*)),
          this,           TQT_SLOT(slotPopulateFinished(KFileTreeViewItem*)));
  addBranch(m_projectDir);
  m_projectDir->urlList = m_projectFiles;  // set list for filter
  if (m_projectName)
    m_projectDir->populate(m_projectDir->rootUrl(), m_projectDir->root());
  else
    m_projectDir->root()->setEnabled(false);

  return m_projectDir;
}


/** slot for context menu */
void ProjectTreeView::slotMenu(KListView *listView, TQListViewItem *item, const TQPoint& point)
{
  Q_UNUSED(listView);
  KURL url = currentURL();
#ifdef ENABLE_CVSSERVICE
  CVSService::ref()->setRepository(m_projectBaseURL.path());
  if (url.isLocalFile())
  {
    TQString path = url.path();
    if (path == m_projectBaseURL.path())
      path += "/.";
    CVSService::ref()->setCurrentFile(path);
  }
  else
    CVSService::ref()->setCurrentFile("");
#endif
  ProjectTreeViewItem *curItem = static_cast<ProjectTreeViewItem *>(currentKFileTreeViewItem());
  if (item && curItem)
  {
    setSelected(item, true);
    if (curItem == curItem->branch()->root())
    {
      m_projectMenu->popup(point);
    } else
    {
      if (!curItem->isDir())
      {
        if (url.fileName().endsWith(toolbarExtension))
        {
          m_fileMenu->setItemVisible(m_openInQuantaId, true);
        } else
        {
          m_fileMenu->setItemVisible(m_openInQuantaId, false);
        }
        m_fileMenu->setItemVisible(m_menuClose, isFileOpen(url));
        insertOpenWithMenu(m_fileMenu, 1);
        m_fileMenu->popup(point);
      } else
      {
        if (m_documentFolderList.contains(url))
          m_folderMenu->setItemChecked(m_setDocumentRootId, true);
        else
          m_folderMenu->setItemChecked(m_setDocumentRootId, false);
        m_folderMenu->popup(point);
      }
    }
  } else
  if (!m_projectName.isNull())
  {
    setSelected(firstChild(), true);
    m_projectMenu->popup(point);
  }
}


/** Sets the project template directory */
void ProjectTreeView::slotNewProjectLoaded(const TQString &name, const KURL &baseURL, const KURL &templateURL)
{
  BaseTreeView::slotNewProjectLoaded(name, baseURL, templateURL); // set m_projectName and m_projectBaseURL
  if (!m_projectName.isNull())
  {
    TQString projectNameStr = m_projectName+" ";
    if (m_projectBaseURL.protocol() == "file")
    {
      projectNameStr += i18n("[local disk]");
    } else
    {
      projectNameStr += "["+m_projectBaseURL.protocol()+"://"+m_projectBaseURL.user()+"@"+m_projectBaseURL.host()+"]";
    }
    m_projectDir->root()->setText(0, projectNameStr);
    m_projectDir->root()->setText(1, m_projectBaseURL.prettyURL());
    setDragEnabled(true);
  }
  else
  {
    m_projectDir->root()->setText(0, i18n("No Project"));
    m_projectDir->root()->setText(1, "");
    setDragEnabled(false);
  }
  m_documentFolderList.clear();
  m_documentFolderList.append(m_projectBaseURL);
}

void ProjectTreeView::slotReloadTree( ProjectList *fileList, bool buildNewTree, const TQStringList &folderToOpen)
{
  m_projectFiles = fileList;
  m_documentFolderList.clear();
  m_documentFolderList.append(m_projectBaseURL);

  KURL url;
  ProjectList::Iterator it( *m_projectFiles );
  for ( ; it.current(); ++it) {
    if (it.current()->documentFolder) {
      url = *(it.current());
      url.adjustPath(-1);
      m_documentFolderList.append( url );
    }
  }

  if (buildNewTree)
  {
    if (m_projectDir)
    {
      removeBranch(m_projectDir);
      m_projectDir = 0L;
    }
    BaseTreeBranch *btb = dynamic_cast<BaseTreeBranch *>(newBranch(m_projectBaseURL));
    if (btb && folderToOpen.count() > 0) {
      btb->folderToOpen = folderToOpen;
      btb->reopenFolder();
      btb->updateOpenFolder();
    }
  } else
  {
    if (m_projectDir){
      m_projectDir->urlList = m_projectFiles;  // set list for filter
      KFileTreeViewItem *item;
      KFileTreeViewItem *rootItem = m_projectDir->root();
      KURL url;
      TQListViewItemIterator iter(this);
      for ( ; iter.current(); ++iter )
      {
        item = dynamic_cast <KFileTreeViewItem*> (iter.current());
        item->setVisible(m_projectFiles->contains(item->url()) || item == rootItem);
      }
      rootItem->setEnabled(true);
    }
  }
}

void ProjectTreeView::slotOpen()
{
  BaseTreeView::slotSelectFile(currentItem());
}

void ProjectTreeView::slotLoadToolbar()
{
 if (currentItem())
 {
   KURL urlToOpen = currentURL();
   if (urlToOpen.fileName().endsWith(toolbarExtension))
   {
      emit loadToolbarFile(urlToOpen);
   }
 }
}

void ProjectTreeView::slotCreateFolder()
{
  bool ok;
  TQString folderName = KInputDialog::getText(i18n("Create New Folder"), i18n("Folder name:"), "", &ok, this);
  if (ok)
  {
     KURL url = currentURL();
     if (currentKFileTreeViewItem()->isDir())
       url.setPath(url.path() + "/" + folderName + "/");
     else
       url.setPath(url.directory() + "/" + folderName +"/");
     if (QExtFileInfo::createDir(url, this))
     {
        emit insertToProject(url);
     }
  }
}

void ProjectTreeView::slotCreateFile()
{
  bool ok;
  TQString fileName = KInputDialog::getText(i18n("Create New File"), i18n("File name:"), "", &ok, this);
  if (ok)
  {
    KURL url = currentURL();
    if (currentKFileTreeViewItem()->isDir())
      url.setPath(url.path() + "/" + fileName);
    else
      url.setPath(url.directory() + "/" + fileName);
    if (QExtFileInfo::exists(url, false, this))
    {
      KMessageBox::error(this, i18n("<qt>Cannot create file, because a file named <b>%1</b> already exists.</qt>").arg(fileName), i18n("Error Creating File"));
      return;
    }
    KTempFile *tempFile = new KTempFile(tmpDir);
    tempFile->setAutoDelete(true);
    tempFile->close();
    if (QExtFileInfo::copy(KURL::fromPathOrURL(tempFile->name()), url))
    {
      emit insertToProject(url);
      emit openFile(url);
    }
    delete tempFile;
  }
}


void ProjectTreeView::slotRemoveFromProject(int askForRemove)
{
  TQListViewItem *item = currentItem();
  if (item)
  {
    KURL url = currentURL();
    TQString nice = QExtFileInfo::toRelative(url, m_projectBaseURL).path();
    nice = KStringHandler::lsqueeze(nice, 60);
    if ( !askForRemove ||
         KMessageBox::warningContinueCancel(this,i18n("<qt>Do you really want to remove <br><b>%1</b><br> from the project?</qt>").arg(nice), i18n("Remove From Project"), KStdGuiItem::remove(), "RemoveFromProject") == KMessageBox::Continue )
    {
      if ( currentKFileTreeViewItem()->isDir() ) url.adjustPath(+1);
      emit removeFromProject(url);
    }
  }
}


void ProjectTreeView::slotUploadSingleURL()
{
  if (currentItem())
  {
    KURL url = currentURL();
    if ( currentKFileTreeViewItem()->isDir() ) url.adjustPath(+1);
    emit uploadSingleURL(url, "", false, false);
  }
}

void ProjectTreeView::slotQuickUploadURL()
{
  if (currentItem())
  {
    KURL url = currentURL();
    if ( currentKFileTreeViewItem()->isDir() ) url.adjustPath(+1);
    emit uploadSingleURL(url, "", true, false);
  }
}

void ProjectTreeView::slotRescan()
{
  emit rescanProjectDir();
  if (!m_projectBaseURL.isLocalFile())
    slotReload();
}

/** Bring up the project options dialog */
void ProjectTreeView::slotOptions()
{
  emit showProjectOptions();
}

/** No descriptions */
void ProjectTreeView::slotUploadProject()
{
  emit uploadProject();
}

void ProjectTreeView::slotPopulateFinished(KFileTreeViewItem* item)
{
  BaseTreeView::slotPopulateFinished(item);
  // populate descriptions
  TQString desc;
  KFileTreeViewItem* file_item;
  ProjectList::Iterator it( *m_projectFiles );
  for ( ; it.current(); ++it)
  {
    desc = it.current()->fileDesc;
    if (! desc.isEmpty())
    {
      file_item = m_projectDir->findTVIByURL( *(it.current()) );
      if (file_item)
        file_item->setText(1, desc);
    }
  }

   if ( m_projectFiles->isEmpty() )
     m_projectDir->root()->setExpandable( false );
   /* FIXME:
    * The below code can cause infinite recursion, possibly over slow links.
    * setOpen call KFileTreeBranch::openURL, that calls KDirListerCache::listDir,
    * that calls KDirListerCache::stop, that emit the signal cancelled, that
    * is connected to KFileTreeBranch::slotCanceled, that emit populateFinished
    * and we are back in this same function with item being the same and
    * everything starts over again. */
//   else
//     m_projectDir->setOpen( true );

}


void ProjectTreeView::itemDescChanged(KFileTreeViewItem* item, const TQString& newDesc)
{
  if (item) {
    item->setText(1, newDesc);
    KURL url = item->url();
    if (item->isDir())
      url.adjustPath(1);
    emit changeFileDescription(url, newDesc);
  }
}

void ProjectTreeView::slotAlwaysUpload()
{
    KFileTreeViewItem *kftvi = currentKFileTreeViewItem();
    if (! kftvi)
      return;
    KURL url = currentURL();
    if (kftvi->isDir())
      url.adjustPath(+1);
    if (m_projectFiles->contains(url) || url == m_projectBaseURL)
    {
       emit changeUploadStatus(url, ProjectURL::AlwaysUpload);
    }
}

void ProjectTreeView::slotNeverUpload()
{
    KFileTreeViewItem *kftvi = currentKFileTreeViewItem();
    if (! kftvi)
      return;
    KURL url = currentURL();
    if (kftvi->isDir())
      url.adjustPath(+1);
    if (m_projectFiles->contains(url) || url == m_projectBaseURL)
    {
       emit changeUploadStatus(url, ProjectURL::NeverUpload);
    }
}

void ProjectTreeView::slotConfirmUpload()
{
    KFileTreeViewItem *kftvi = currentKFileTreeViewItem();
    if (! kftvi)
      return;
    KURL url = currentURL();
    if (kftvi->isDir())
      url.adjustPath(+1);
    if (m_projectFiles->contains(url) || url == m_projectBaseURL)
    {
       emit changeUploadStatus(url, ProjectURL::ConfirmUpload);
    }
}

void ProjectTreeView::slotUploadMenuAboutToShow()
{
    m_uploadStatusMenu->setItemChecked(m_alwaysUploadId, false);
    m_uploadStatusMenu->setItemChecked(m_neverUploadId, false);
    m_uploadStatusMenu->setItemChecked(m_confirmUploadId, false);
    KFileTreeViewItem *kftvi = currentKFileTreeViewItem();
    if (! kftvi)
      return;
    KURL url = currentURL();
    if (kftvi->isDir())
      url.adjustPath(+1);
    ProjectURL *proUrl = m_projectFiles->find( url );
    if (proUrl)
    {
        switch (proUrl->uploadStatus)
        {
            case ProjectURL::NeverUpload:
               {
                 m_uploadStatusMenu->setItemChecked(m_neverUploadId, true);
                 break;
               }
            case ProjectURL::ConfirmUpload:
               {
                 m_uploadStatusMenu->setItemChecked(m_confirmUploadId, true);
                 break;
               }
            case ProjectURL::AlwaysUpload:
            default:
               {
                 m_uploadStatusMenu->setItemChecked(m_alwaysUploadId, true);
                 break;
               }
        }
    }
}

void ProjectTreeView::slotChangeDocumentFolderStatus()
{
    KFileTreeViewItem *kftvi = currentKFileTreeViewItem();
    if (! kftvi)
      return;
    KURL url = currentURL();
    if (kftvi->isDir())
      url.adjustPath(+1);
    if (!m_documentFolderList.contains(currentURL()))
    {
      m_documentFolderList.append(currentURL());
      emit changeUploadStatus(url, ProjectURL::AlwaysUpload);
      emit changeDocumentFolderStatus(url, true);
    } else
    {
      m_documentFolderList.remove(currentURL());
      emit changeUploadStatus(url, false);
    }
    currentItem()->repaint();
}

bool ProjectTreeView::isDocumentFolder(const KURL &url)
{
   return (m_documentFolderList.contains(url) > 0);
}


void ProjectTreeView::slotRenameItem(TQListViewItem* kftvi, const TQString& newText, int col)
{
  if (!kftvi)
    return;

  if (col == 1) {
    itemDescChanged(dynamic_cast <KFileTreeViewItem*> (kftvi), newText);
  } else {
    BaseTreeView::slotRenameItem(kftvi, newText, col);
  }
}


FileInfoDlg* ProjectTreeView::addFileInfoPage(KPropertiesDialog* propDlg)
{
  FileInfoDlg* dlg = BaseTreeView::addFileInfoPage(propDlg);
  if (dlg) {
    dlg->fileDescLbl->show();
    dlg->fileDesc->show();
  }
  return dlg;
}


void ProjectTreeView::plugCVSMenu()
{
#ifdef ENABLE_CVSSERVICE
  m_fileMenu->insertSeparator();
  m_fileMenu->insertItem(SmallIcon("cervisia"), i18n("C&VS"), CVSService::ref()->menu());
  m_folderMenu->insertSeparator();
  m_folderMenu->insertItem(SmallIcon("cervisia"), i18n("C&VS"), CVSService::ref()->menu());
  m_projectMenu->insertSeparator();
  m_projectMenu->insertItem(SmallIcon("cervisia"), i18n("C&VS"), CVSService::ref()->menu());
#endif

}


void ProjectTreeView::slotViewActivated(const KURL& url)
{
  if (! m_projectDir) return;

  KFileTreeViewItem* item = m_projectDir->findTVIByURL(url);
  if (item){
    ensureItemVisible(item);
    setSelected(item, true);
  }
}

#include "projecttreeview.moc"