summaryrefslogtreecommitdiffstats
path: root/quanta/treeviews/servertreeview.cpp
blob: 88b4533e52bead92146748b013289c46e957a167 (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
/***************************************************************************
                          filestreeview.cpp  -  description
                             -------------------
    begin                : Thu Jun 1 2000
    copyright            : (C) 2000 by Dmitry Poplavsky & Alexander Yakovlev & Eric Laffoon <pdima@users.sourceforge.net,yshurik@linuxfan.com,sequitur@easystreet.com>
                           (C) 2001-2004 Andras Mantia <amantoa@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.                                   *
 *                                                                         *
 ***************************************************************************/

// TQt includes
#include <tqpainter.h>

// KDE includes
#include <kdebug.h>
#include <tdelocale.h>
#include <kiconloader.h>
#include <kopenwith.h>
#include <tdemessagebox.h>
#include <tdepopupmenu.h>
#include <tdefiledialog.h>
#include <kprogress.h>
#include <kurl.h>

// app includes
#include "servertreeview.h"
#include "resource.h"
#include "project.h"
#include "qextfileinfo.h"


ServerTreeViewItem::ServerTreeViewItem( KFileTreeViewItem *parent, KFileItem* item, KFileTreeBranch *brnch )
: BaseTreeViewItem( parent, item, brnch)
{
}

void ServerTreeViewItem::paintCell(TQPainter *p, const TQColorGroup &cg,
                                   int column, int width, int align)
{
  TQColorGroup _cg( cg );
  KURL baseURL = Project::ref()->projectBaseURL();
  KURL relURL = baseURL;
  relURL.setPath(QExtFileInfo::toRelative(url(), branch()->url()).path());
  KURL url = QExtFileInfo::toAbsolute(relURL, baseURL);
  if ( !Project::ref()->contains(url) )
  {
    TQFont f = p->font();
    f.setItalic(true);
    p->setFont(f);
    int h, s, v;
    p->pen().color().getHsv(&h, &s, &v);
    v = (v < 155 ? v + 100 : 255);
    _cg.setColor(TQColorGroup::Text, TQColor(h, s, v, TQColor::Hsv));
  };
  BaseTreeViewItem::paintCell( p, _cg, column, width, align );
}

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

KFileTreeViewItem* ServerTreeBranch::createTreeViewItem(KFileTreeViewItem *parent, KFileItem *fileItem )
{
  BaseTreeViewItem  *tvi = 0;
  if( parent && fileItem )
  {
    tvi = new ServerTreeViewItem( parent, fileItem, this );
  }
  else
    kdDebug(24000) << "ServerTreeBranch::createTreeViewItem: Have no parent" << endl;
  return tvi;
}

/////////////////////////////////////////////////////////////////////////////////////
//
// ServerTreeView implementation
//
//
ServerTreeView::ServerTreeView(TDEConfig *config, TQWidget *parent, const KURL &url, const char *name)
  : BaseTreeView(parent, name)
{
  setAcceptDrops(true);
  setDragEnabled(true);

  m_config = config;
  m_config->setGroup("General Options");
  // I must read this here because quanta_init has not done it yet
  qConfig.showHiddenFiles = m_config->readBoolEntry("Show Hidden Files", true);

  m_fileMenu = new TDEPopupMenu();

  m_fileMenu->insertItem(SmallIcon("fileopen"), i18n("&Open"), this ,TQT_SLOT(slotOpen()));
  m_fileMenu->insertItem(i18n("Open &With..."), this, TQT_SLOT(slotOpenWith()));
  m_menuClose = m_fileMenu->insertItem(SmallIcon("fileclose"), i18n("Clos&e"), this, TQT_SLOT(slotClose()));
  m_fileMenu->insertSeparator();
//  m_insertFileInProject = m_fileMenu->insertItem(i18n("&Insert in Project..."), this, TQT_SLOT(slotInsertInProject()));
  m_fileMenu->insertItem(SmallIcon("editcopy"), i18n("&Copy"), this, TQT_SLOT(slotCopy()));
  m_fileMenu->insertItem(SmallIcon("editdelete"), i18n("&Delete"), this, TQT_SLOT(slotDelete()));
  m_fileMenu->insertItem(i18n("Re&name"), this, TQT_SLOT(slotStartRename()));
  m_fileMenu->insertSeparator();
  m_fileMenu->insertItem(SmallIcon("info"), i18n("&Properties"), this, TQT_SLOT(slotProperties()));

  m_folderMenu = new TDEPopupMenu();

//  m_insertFolderInProject = m_folderMenu->insertItem(i18n("&Insert in Project..."), this, TQT_SLOT(slotInsertDirInProject()));
  m_folderMenu->insertItem(SmallIcon("editcopy"), i18n("&Copy"), this, TQT_SLOT(slotCopy()));
  m_menuPasteFolder = m_folderMenu->insertItem(SmallIcon("editpaste"), i18n("&Paste"), this, TQT_SLOT(slotPaste()));
  m_menuDel = m_folderMenu->insertItem( SmallIcon("editdelete"), i18n("&Delete"), this, TQT_SLOT(slotDelete()));
  m_renameId = m_folderMenu->insertItem(i18n("Re&name"), this, TQT_SLOT(slotStartRename()));
  m_folderMenu->insertSeparator();
  m_folderMenu->insertItem(SmallIcon("info"), i18n("&Properties"), this, TQT_SLOT(slotProperties()));
  m_reloadMenuId = m_folderMenu->insertItem(SmallIcon("revert"), i18n("&Reload"), this, TQT_SLOT(slotReload()));

  addColumn(i18n("Upload Tree"), -1);
  addColumn("");

  connect(this, TQT_SIGNAL(open(TQListViewItem *)),
          this, TQT_SLOT(slotSelectFile(TQListViewItem *)));
  connect(this, TQT_SIGNAL(contextMenu(TDEListView*, TQListViewItem*, const TQPoint&)),
          this, TQT_SLOT(slotMenu(TDEListView*, TQListViewItem*, const TQPoint&)));
  connect(Project::ref(), TQT_SIGNAL(reloadTree(ProjectList *, bool, const TQStringList &)),
          this, TQT_SLOT(slotReloadTree(ProjectList *, bool, const TQStringList &)));

  restoreLayout(m_config, "UploadTreeView");  // a fixed name only for the tooltip configuration
  // 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);
  newBranch(url);
}

ServerTreeView::~ServerTreeView()
{
}

KFileTreeBranch* ServerTreeView::newBranch(const KURL& url)
{
  KURL branchURL = url;
  branchURL.adjustPath(+1);
  BaseTreeBranch* newBrnch = 0;
  newBrnch = new ServerTreeBranch(this, branchURL, branchURL.prettyURL(), SmallIcon("up"), true);
  newBrnch->setShowingDotFiles(qConfig.showHiddenFiles);
  addBranch(newBrnch);
  return newBrnch;
}


/** RMB pressed, bring up the menu */
void ServerTreeView::slotMenu(TDEListView* listView, TQListViewItem *item, const TQPoint &point)
{
  Q_UNUSED(listView);
  if (item)
  {
    setSelected(item, true);
    KFileTreeViewItem *curItem = currentKFileTreeViewItem();
    if ( !curItem->isDir() )
    {
      m_fileMenu->setItemVisible(m_menuClose, isFileOpen(currentURL()));
      m_fileMenu->popup(point);
    } else {
      m_folderMenu->setItemVisible(m_menuPasteFolder, isPathInClipboard());
      bool root = (curItem == curItem->branch()->root());
      m_folderMenu->setItemVisible(m_menuDel, ! root);
      m_folderMenu->setItemVisible(m_reloadMenuId, root);
      m_folderMenu->setItemVisible(m_renameId, ! root);
      m_folderMenu->popup(point);
   }
 }
}


void ServerTreeView::slotReloadTree( ProjectList *fileList, bool buildNewTree, const TQStringList &folderToOpen)
{
  Q_UNUSED(fileList);
  Q_UNUSED(buildNewTree);
  Q_UNUSED(folderToOpen);
  
  TQListViewItemIterator iter(this);
  for ( ; iter.current(); ++iter )
  {
    iter.current()->repaint();
  }
}

#include "servertreeview.moc"