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
|
#include "toolsconfig.h"
#include <qapplication.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlistbox.h>
#include <qpushbutton.h>
#include <qheader.h>
#include <kapplication.h>
#include <kdesktopfile.h>
#include <kdialog.h>
#include <kiconloader.h>
#include <klocale.h>
#include "tools_part.h"
#include "kapplicationtree.h"
ToolsConfig::ToolsConfig(QWidget *parent, const char *name)
: QWidget(parent, name), _tree(0)
{
_entries.setAutoDelete(true);
}
void ToolsConfig::showEvent(QShowEvent *e)
{
QWidget::showEvent(e);
if (!_tree)
{
QApplication::setOverrideCursor(Qt::waitCursor);
QHBoxLayout *hbox = new QHBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint());
QVBoxLayout *vbox = new QVBoxLayout(hbox);
_tree = new KDevApplicationTree(this);
_tree->header()->hide();
QLabel *l = new QLabel(_tree, i18n("&Applications:"), this);
l->show();
_tree->show();
vbox->addWidget(l);
vbox->addWidget(_tree);
vbox = new QVBoxLayout(hbox);
_toList = new QPushButton(QApplication::reverseLayout() ? "<<" : ">>", this);
_toList->show();
vbox->addWidget(_toList);
connect(_toList, SIGNAL(clicked()), this, SLOT(toList()));
_toTree = new QPushButton(QApplication::reverseLayout() ? ">>" : "<<", this);
_toTree->show();
vbox->addWidget(_toTree);
connect(_toTree, SIGNAL(clicked()), this, SLOT(toTree()));
vbox = new QVBoxLayout(hbox);
_list = new QListBox(this);
l = new QLabel(_list, i18n("&Tools menu:"), this);
l->show();
_list->show();
vbox->addWidget(l);
vbox->addWidget(_list);
QApplication::restoreOverrideCursor();
}
fill();
checkButtons();
connect(_tree, SIGNAL(selectionChanged()), this, SLOT(checkButtons()));
connect(_list, SIGNAL(selectionChanged()), this, SLOT(checkButtons()));
}
void ToolsConfig::checkButtons()
{
_toList->setEnabled(_tree->selectedItem() && !_tree->selectedItem()->firstChild());
_toTree->setEnabled(_list->currentItem() >= 0 && _list->currentItem() < (int)_list->count());
}
void ToolsConfig::fill()
{
_entries.clear();
KConfig *config = ToolsFactory::instance()->config();
config->setGroup("Tools");
QStringList list = config->readListEntry("Tools");
for (QStringList::Iterator it = list.begin(); it != list.end(); ++it)
add(*it);
}
void ToolsConfig::add(const QString &desktopFile)
{
KDesktopFile df(desktopFile, true);
if (df.readName().isEmpty())
return;
Entry *entry = new Entry;
if (!df.readIcon().isEmpty())
entry->icon = BarIcon(df.readIcon());
entry->name = df.readName();
entry->desktopFile = desktopFile;
_entries.append(entry);
updateList();
checkButtons();
}
void ToolsConfig::toList()
{
KDevAppTreeListItem *item = dynamic_cast<KDevAppTreeListItem*>(_tree->selectedItem());
if (item && !item->desktopEntryPath().isEmpty())
add(item->desktopEntryPath());
checkButtons();
}
void ToolsConfig::toTree()
{
_entries.remove(_list->currentItem());
updateList();
checkButtons();
}
void ToolsConfig::accept()
{
KConfig *config = ToolsFactory::instance()->config();
config->setGroup("Tools");
QStringList l;
QPtrListIterator<Entry> it(_entries);
for ( ; it.current(); ++it)
l.append(it.current()->desktopFile);
config->writeEntry("Tools", l);
config->sync();
}
void ToolsConfig::updateList()
{
_list->setUpdatesEnabled(false);
_list->clear();
QPtrListIterator<Entry> it(_entries);
for ( ; it.current(); ++it)
_list->insertItem(it.current()->icon, it.current()->name);
_list->setUpdatesEnabled(true);
_list->repaint();
}
#include "toolsconfig.moc"
|