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
|
/***************************************************************************
* Copyright (C) 2005-2007 by Rajko Albrecht *
* ral@alwins-world.de *
* *
* 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. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "filelistviewitem.h"
#include "kdesvnfilelist.h"
#include "src/settings/kdesvnsettings.h"
#include "helpers/sub2qt.h"
#include "src/svnqt/status.hpp"
#include "src/svnqt/revision.hpp"
#include "src/svnqt/exception.hpp"
#include "src/svnqt/url.hpp"
#include "fronthelpers/widgetblockstack.h"
#include <klocale.h>
#include <kiconloader.h>
#include <kfileitem.h>
#include <kdebug.h>
#include <kconfig.h>
#include <tqfileinfo.h>
#include <tqpainter.h>
const int FileListViewItem::COL_ICON = 0;
const int FileListViewItem::COL_NAME = 0;
const int FileListViewItem::COL_STATUS = 1;
const int FileListViewItem::COL_LAST_REV = 2;
const int FileListViewItem::COL_LAST_AUTHOR = 3;
const int FileListViewItem::COL_LAST_DATE = 4;
const int FileListViewItem::COL_IS_LOCKED = 5;
//const int FileListViewItem::COL_CURRENT_REV = 5;
FileListViewItem::FileListViewItem(kdesvnfilelist*_parent,const svn::StatusPtr&_stat)
: KListViewItem(_parent),SvnItem(_stat),
sortChar(0),
m_Ksvnfilelist(_parent)
{
m_SvnWrapper = _parent->m_SvnWrapper;
init();
}
FileListViewItem::FileListViewItem(kdesvnfilelist*_parent,FileListViewItem*_parentItem,const svn::StatusPtr&_stat)
: KListViewItem(_parentItem),SvnItem(_stat),
sortChar(0),
m_Ksvnfilelist(_parent)
{
m_SvnWrapper = _parent->m_SvnWrapper;
init();
}
SvnActions*FileListViewItem::getWrapper()const
{
return m_SvnWrapper;
}
void FileListViewItem::init()
{
setText(COL_NAME,shortName());
sortChar = isDir()?1:3;
setExpandable(isDir());
if (shortName()[0]=='.') --sortChar;
update();
}
void FileListViewItem::setOpen(bool o)
{
if (o && childCount()==0) {
{
WidgetBlockStack a(m_Ksvnfilelist);
m_Ksvnfilelist->slotItemRead(this);
}
m_Ksvnfilelist->setFocus();
}
KListViewItem::setOpen(o);
}
void FileListViewItem::setOpenNoBlock(bool o)
{
if (o && childCount()==0) {
{
m_Ksvnfilelist->slotItemRead(this);
}
}
KListViewItem::setOpen(o);
}
FileListViewItem::~FileListViewItem()
{
if (isSelected()) {
/*
when item is selected and deleted signal selectionChanged isn't emitted
in TQListView anymore and let kdesvn crash.
*/
setSelected(false);
m_Ksvnfilelist->selectionChanged();
}
}
void FileListViewItem::setStat(const svn::StatusPtr&stat)
{
SvnItem::setStat(stat);
init();
}
void FileListViewItem::refreshStatus(bool childs,TQPtrList<SvnItem>*exclude,bool depsonly)
{
FileListViewItem*it;
if (!depsonly) {
if (!m_Ksvnfilelist->refreshItem(this)) {
return;
}
}
if (!isValid()) {
return;
}
it = static_cast<FileListViewItem*>(parent());
if (!childs) {
if (it && (!exclude || exclude->find(it)==-1)) {
it->refreshStatus(false,exclude);
}
} else if (firstChild()){
it = static_cast<FileListViewItem*>(firstChild());
while (it) {
if (!exclude || exclude->find(it)==-1) {
it->refreshStatus(true,exclude);
}
it = static_cast<FileListViewItem*>(it->nextSibling());
}
}
repaint();
}
void FileListViewItem::makePixmap()
{
int size = Kdesvnsettings::listview_icon_size();
bool overlay = Kdesvnsettings::display_overlays();
TQPixmap pm;
if (m_Pixmap.isNull()) {
pm = getPixmap(size,overlay);
} else {
pm = getPixmap(m_Pixmap,size,overlay);
}
setPixmap(COL_ICON,pm);
}
void FileListViewItem::setPreviewPix(const TQPixmap& pixmap)
{
if (pixmap.isNull()) return;
m_Pixmap = pixmap;
int size = Kdesvnsettings::listview_icon_size();
bool overlay = Kdesvnsettings::display_overlays();
TQPixmap pm = getPixmap(pixmap,size,overlay);
setPixmap(COL_ICON,pm);
}
bool FileListViewItem::isParent(TQListViewItem*which)
{
if (!which) return false;
TQListViewItem*item = this;
while ( (item=item->parent())) {
if (item==which) {
return true;
}
}
return false;
}
void FileListViewItem::update()
{
makePixmap();
if (!isVersioned()) {
setText(COL_STATUS,i18n("Not versioned"));
return;
}
setText(COL_STATUS,infoText());
setText(COL_LAST_AUTHOR,cmtAuthor());
setText(COL_LAST_DATE,KGlobal::locale()->formatDateTime(fullDate()));
setText(COL_LAST_REV,TQString("%1").arg(cmtRev()));
setText(COL_IS_LOCKED,lockOwner());
}
int FileListViewItem::compare( TQListViewItem* item, int col, bool ascending ) const
{
FileListViewItem* k = static_cast<FileListViewItem*>( item );
if ( sortChar != k->sortChar ) {
// Dirs are always first, even when sorting in descending order
return !ascending ? k->sortChar - sortChar : sortChar - k->sortChar;
}
if (col==COL_LAST_DATE) {
return fullDate().secsTo(k->fullDate());
}
if (col==COL_LAST_REV) {
return k->cmtRev()-cmtRev();
}
if (Kdesvnsettings::case_sensitive_sort()) {
if (Kdesvnsettings::locale_is_casesensitive()) {
return text(col).localeAwareCompare(k->text(col));
}
return text(col).compare(k->text(col));
} else {
return text(col).lower().localeAwareCompare(k->text(col).lower());
}
}
void FileListViewItem::removeChilds()
{
TQListViewItem*temp;
while ((temp=firstChild())) {
delete temp;
}
}
void FileListViewItem::updateStatus(const svn::StatusPtr&s)
{
setStat(s);
}
SvnItem* FileListViewItem::getParentItem()const
{
return static_cast<FileListViewItem*>(parent());
}
/*!
\fn FileListViewItem::getParentDir()const
*/
TQString FileListViewItem::getParentDir()const
{
SvnItem*temp = getParentItem();
if (!temp) return TQString();
return temp->fullName();
}
void FileListViewItem::paintCell(TQPainter *p, const TQColorGroup &cg, int column, int width, int alignment)
{
bool colors = Kdesvnsettings::colored_state();
if (!colors||m_bgColor==NONE) {
KListViewItem::paintCell(p,cg,column,width,alignment);
return;
}
TQColorGroup _cg = cg;
TQColor _bgColor;
switch(m_bgColor) {
case UPDATES:
_bgColor = Kdesvnsettings::color_need_update();
break;
case LOCKED:
_bgColor = Kdesvnsettings::color_locked_item();
break;
case ADDED:
_bgColor = Kdesvnsettings::color_item_added();
break;
case DELETED:
_bgColor = Kdesvnsettings::color_item_deleted();
break;
case MODIFIED:
_bgColor = Kdesvnsettings::color_changed_item();
break;
case MISSING:
_bgColor = Kdesvnsettings::color_missed_item();
break;
case NOTVERSIONED:
_bgColor = Kdesvnsettings::color_notversioned_item();
break;
case CONFLICT:
_bgColor = Kdesvnsettings::color_conflicted_item();
break;
case NEEDLOCK:
_bgColor = Kdesvnsettings::color_need_lock();
break;
default:
KListViewItem::paintCell(p,cg,column,width,alignment);
return;
break;
}
const TQPixmap *pm = listView()->viewport()->backgroundPixmap();
if (pm && !pm->isNull()) {
_cg.setBrush(TQColorGroup::Base, TQBrush(_bgColor, *pm));
TQPoint o = p->brushOrigin();
p->setBrushOrigin( o.x()-listView()->contentsX(), o.y()-listView()->contentsY() );
} else {
if (listView()->viewport()->backgroundMode()==TQt::FixedColor) {
_cg.setColor(TQColorGroup::Background,_bgColor);
} else {
_cg.setColor(TQColorGroup::Base,_bgColor);
}
}
TQListViewItem::paintCell(p, _cg, column, width, alignment);
}
const svn::Revision&FileListViewItem::correctPeg()const
{
return m_Ksvnfilelist->remoteRevision();
}
FileListViewItem*FileListViewItem::findChild(const TQString&aName)
{
FileListViewItem*_item = (FileListViewItem*)firstChild();
while (_item) {
if (_item->fullName()==aName) {
return _item;
}
_item = (FileListViewItem*)_item->nextSibling();
}
return 0L;
}
|