File: IceListViewItem.cpp

package info (click to toggle)
icemc 0.2.4-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 256 kB
  • ctags: 247
  • sloc: cpp: 2,211; makefile: 44
file content (243 lines) | stat: -rw-r--r-- 6,338 bytes parent folder | download | duplicates (2)
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
/**
 * IceMC - a menu editor for IceWM
 * Copyright (c) 2000 Georg Mittendorfer
 */

#include "IceListView.h"

#include "IceFileSearch.h"
#include "IceMainWindow.h"

#include <qpixmap.h>

#include "noIcon.xpm"

//////////////////////////////////////////////
// constructors & destructor
//////////////////////////////////////////////

IceListViewItem::IceListViewItem ( IceListView* parent) : QListViewItem (parent) 
{ 
  color = QColor(0,0,0);
}

IceListViewItem::IceListViewItem ( IceListView* parent, QString infoStr, QString label1,
				   QString label2, QString label3, QString label4, 
				   QString label5, QString label6, QString label7, 
				   QString label8 )
  : QListViewItem ( parent, label1, label2, label3, label4, label5, label6, label7, label8 ), info(infoStr)
{ 
  color = QColor(0,0,0);
}

IceListViewItem::IceListViewItem ( IceListView* parent, IceListViewItem* after, QString infoStr, QString label1,
				   QString label2, QString label3, QString label4, QString label5, QString label6,
				   QString label7, QString label8 )
  : QListViewItem ( parent, after, label1, label2, label3, label4, label5, label6, label7, label8 ), info(infoStr)
{ 
  color = QColor(0,0,0);
}

IceListViewItem::IceListViewItem ( IceListViewItem* parent, IceListViewItem* after, QString infoStr, QString label1,
				   QString label2, QString label3, QString label4, QString label5, QString label6,
				   QString label7, QString label8 )
  : QListViewItem ( parent, after, label1, label2, label3, label4, label5, label6, label7, label8 ), info(infoStr) 
{ 
  color = QColor(0,0,0);
}

IceListViewItem::~IceListViewItem() // virtual
{
}

/////////////////////////////////////////////
// public methods
/////////////////////////////////////////////

IceListViewItem* IceListViewItem::firstChild() const // virtual
{
  return (IceListViewItem*) (QListViewItem::firstChild());
}

IceListViewItem* IceListViewItem::nextSibling() const // virtual
{
  return (IceListViewItem*) (QListViewItem::nextSibling());
}

IceListViewItem* IceListViewItem::parent() const // virtual 
{
  return (IceListViewItem*) (QListViewItem::parent());
}

IceListViewItem* IceListViewItem::itemAbove() // virtual
{
  return (IceListViewItem*) (QListViewItem::itemAbove());
}

IceListViewItem* IceListViewItem::itemBelow() // virtual
{
  return (IceListViewItem*) (QListViewItem::itemBelow());
}
 
QString IceListViewItem::getInfo() const // virtual 
{
  return info;
}

QColor IceListViewItem::getColor() const // virtual
{
  return color;
}

void IceListViewItem::setInfo(QString infoStr) // virtual
{
  if (infoStr != info) {
    this->setExecState();
    info = infoStr;
  }
}

void IceListViewItem::setColor(QColor newColor) // virtual 
{
  color = newColor;
}

void IceListViewItem::paintCell ( QPainter * p, const QColorGroup & cg, int column, int width, int align ) // virtual
{
  QColorGroup colorGroup(cg);
  colorGroup.setColor(QColorGroup::Text,color);
  QListViewItem::paintCell(p,colorGroup,column,width,align);
}

// deepCopy makes a deep copy of 'this' making 'copy' the parent item of the copy
// IMPORTANT: 'this' and 'copy' have to be members of a ListView !
void IceListViewItem::deepCopy(IceListViewItem* copy) // virtual
{
  ;//qDebug("DEBUG: IceListViewItem::deepCopy(...)");

  if (copy) {

    IceListViewItem* thisChild;
    IceListViewItem* tempItem;
    
    copy->setInfo(this->getInfo());
    copy->setText(0,this->text(0));
    copy->setText(1,this->text(1));
    copy->setText(2,this->text(2));
    
    if (this->isExpandable())
      copy->setExpandable(true);
    
    thisChild = this->firstChild();
    
    if (thisChild) {
      tempItem = copy;
      thisChild->deepCopyFolder(tempItem);
    }
  }
  else
    qWarning("WARNING: IceListViewItem::deepCopy(...) null pointer");
}

bool IceListViewItem::setExecState() // virtual
{
  QString exec, temp;
  bool isExec = false;
  
  temp = this->getInfo();
  if ((temp == "prog") || (temp == "restart")) {
    exec = this->text(2);
    if (exec.contains(' ') > 0) {
      int count = 0;
      temp = "";
      while (exec.at(count) != ' ') {
	temp += exec.at(count);
	count++;
      }
      exec = temp;
    }
    IceFileSearch* search = new IceFileSearch();
    if (search->fileExecutable(exec, IceListView::path) != "") { // executable
      this->setColor(IceListView::executable);
      isExec = true;
      ;//qDebug("DEBUG: executable");
    }
    else {
      this->setColor(IceListView::notExecutable);
    }
    delete search;
  }
  else {
    if (temp == "menu") {
      this->setColor(IceListView::notExecutable); // warum da? auch in set infostr
    } else {
      this->setColor(IceListView::executable);
      isExec = true;
    } 
  } // end if

  return isExec;
}

void IceListViewItem::setIcon() // virtual
{
  QString icon;
  IceFileSearch* search = new IceFileSearch();

  icon = search->iconReadable(this->text(1), IceListView::iconPath);
  delete search;
  
  if (this->getInfo() == "separator")
    this->setPixmap(0,0);
  else if (icon != "")
    this->setPixmap(0,QPixmap(icon));
  else
    this->setPixmap(0,QPixmap(noIcon));

  ;//qDebug("DEBUG: setIcon: " + this->text(0));
}

//////////////////////////////////////////////////////////////
// protected methods
//////////////////////////////////////////////////////////////

void IceListViewItem::deepCopyFolder(IceListViewItem* copy) // virtual
{
  ;//qDebug("DEBUG: IceListViewItem::deepCopyFolder() ");
  IceListViewItem* sibling;
  IceListViewItem* item;
  IceListViewItem* tempChild;
  IceListViewItem* tempItem;

  item = new IceListViewItem(copy,copy,this->getInfo(),this->text(0),this->text(1),this->text(2));
  if (this->isExpandable())
    item->setExpandable(true);

  // deepcopy this if it is a folder
  if ((tempChild = this->firstChild())) {
    tempItem = item;
    tempChild->deepCopyFolder(tempItem);
  }

  sibling = this;

  // copy siblings
  while ((sibling = sibling->nextSibling())) {
    item = new IceListViewItem(copy,item,sibling->getInfo(),sibling->text(0),sibling->text(1),sibling->text(2));
    if ((tempChild = sibling->firstChild())) {
      tempItem = item;
      tempChild->deepCopyFolder(tempItem);
    }
    else if (sibling->isExpandable()) // just test when 'else' 
      item->setExpandable(true);      // (if child then automatically expandable)
  }
}