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 <tqapplication.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqlistbox.h>
#include <tqpushbutton.h>
#include <tqheader.h>
#include <tdeapplication.h>
#include <kdesktopfile.h>
#include <kdialog.h>
#include <kiconloader.h>
#include <tdelocale.h>
#include "tools_part.h"
#include "kapplicationtree.h"
ToolsConfig::ToolsConfig(TQWidget *parent, const char *name)
: TQWidget(parent, name), _tree(0)
{
_entries.setAutoDelete(true);
}
void ToolsConfig::showEvent(TQShowEvent *e)
{
TQWidget::showEvent(e);
if (!_tree)
{
TQApplication::setOverrideCursor(TQt::waitCursor);
TQHBoxLayout *hbox = new TQHBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint());
TQVBoxLayout *vbox = new TQVBoxLayout(hbox);
_tree = new KDevApplicationTree(this);
_tree->header()->hide();
TQLabel *l = new TQLabel(_tree, i18n("&Applications:"), this);
l->show();
_tree->show();
vbox->addWidget(l);
vbox->addWidget(_tree);
vbox = new TQVBoxLayout(hbox);
_toList = new TQPushButton(TQApplication::reverseLayout() ? "<<" : ">>", this);
_toList->show();
vbox->addWidget(_toList);
connect(_toList, TQ_SIGNAL(clicked()), this, TQ_SLOT(toList()));
_toTree = new TQPushButton(TQApplication::reverseLayout() ? ">>" : "<<", this);
_toTree->show();
vbox->addWidget(_toTree);
connect(_toTree, TQ_SIGNAL(clicked()), this, TQ_SLOT(toTree()));
vbox = new TQVBoxLayout(hbox);
_list = new TQListBox(this);
l = new TQLabel(_list, i18n("&Tools menu:"), this);
l->show();
_list->show();
vbox->addWidget(l);
vbox->addWidget(_list);
TQApplication::restoreOverrideCursor();
}
fill();
checkButtons();
connect(_tree, TQ_SIGNAL(selectionChanged()), this, TQ_SLOT(checkButtons()));
connect(_list, TQ_SIGNAL(selectionChanged()), this, TQ_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();
TDEConfig *config = ToolsFactory::instance()->config();
config->setGroup("Tools");
TQStringList list = config->readListEntry("Tools");
for (TQStringList::Iterator it = list.begin(); it != list.end(); ++it)
add(*it);
}
void ToolsConfig::add(const TQString &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()
{
TDEConfig *config = ToolsFactory::instance()->config();
config->setGroup("Tools");
TQStringList l;
TQPtrListIterator<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();
TQPtrListIterator<Entry> it(_entries);
for ( ; it.current(); ++it)
_list->insertItem(it.current()->icon, it.current()->name);
_list->setUpdatesEnabled(true);
_list->repaint();
}
#include "toolsconfig.moc"
|