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
|
/***************************************************************************
quantaplugineditor.cpp - description
-------------------
begin : Fri Sep 20 2002
copyright : (C) 2002 by Marc Britton <consume@optushome.com.au>
(C) 2003 by Andras Mantia <amantia@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. *
* *
***************************************************************************/
/* KDE INCLUDES */
#include <kfiledialog.h>
#include <kiconloader.h>
#include <kglobal.h>
#include <klocale.h>
#include <kicondialog.h>
#include <kdialogbase.h>
/* QT INCLUDES */
#include <tqwidget.h>
#include <tqobject.h>
#include <tqdict.h>
#include <tqcheckbox.h>
#include <tqpushbutton.h>
#include <tqlineedit.h>
#include <tqcombobox.h>
#include <tqlistview.h>
/* OTHER INCLUDES */
#include "quantaplugineditor.h"
#include "quantaplugin.h"
#include "quantapluginconfig.h"
#include "pluginconfig.h"
#include "plugineditor.h"
#include "resource.h"
QuantaPluginEditor::QuantaPluginEditor(TQWidget *a_parent, const char *a_name)
: KDialogBase(a_parent, a_name, true, i18n("Edit Plugins"), KDialogBase::Ok | KDialogBase::Cancel)
{
// m_plugins.setAutoDelete(true);
m_pluginEditorWidget = new PluginEditor(this);
setMainWidget(m_pluginEditorWidget);
m_pluginEditorWidget->pluginList->setSelectionMode(TQListView::Single);
m_pluginEditorWidget->pluginList->setAllColumnsShowFocus(true);
m_pluginEditorWidget->pluginList->setColumnAlignment(2, Qt::AlignHCenter);
connect(this, TQT_SIGNAL(pluginsChanged()), TQT_SLOT(refreshPlugins()));
connect(m_pluginEditorWidget->refreshButton, TQT_SIGNAL(clicked()), TQT_SLOT(refreshPlugins()));
connect(m_pluginEditorWidget->addButton, TQT_SIGNAL(clicked()), TQT_SLOT(addPlugin()));
connect(m_pluginEditorWidget->removeButton, TQT_SIGNAL(clicked()), TQT_SLOT(removePlugin()));
connect(m_pluginEditorWidget->addSearchPathButton, TQT_SIGNAL(clicked()), TQT_SLOT(addSearchPath()));
connect(m_pluginEditorWidget->configureButton, TQT_SIGNAL(clicked()), TQT_SLOT(configurePlugin()));
connect(m_pluginEditorWidget->pluginList, TQT_SIGNAL(doubleClicked(TQListViewItem*, const TQPoint&, int)),
TQT_SLOT(configurePlugin(TQListViewItem*, const TQPoint&, int)));
}
QuantaPluginEditor::~QuantaPluginEditor()
{
}
TQDict<QuantaPlugin> QuantaPluginEditor::plugins()
{
return m_plugins;
}
void QuantaPluginEditor::addPlugin()
{
// new plugin config menu
// create new plugin and add to list
QuantaPluginConfig *configDlg = new QuantaPluginConfig(this, "pluginConfig");
PluginConfig *configWidget = static_cast<PluginConfig*>(configDlg->mainWidget());
if(configDlg->exec())
{
// plugin accepted, create the proper type
QuantaPlugin *newPlugin = 0;
newPlugin = new QuantaPlugin();
newPlugin->setPluginName(configWidget->pluginName->text());
newPlugin->setFileName(configWidget->pluginFileName->text());
newPlugin->setLocation(configWidget->location->text());
newPlugin->setOutputWindow(configWidget->outputWindow->currentText());
newPlugin->setStandard(false);
newPlugin->setIcon(configWidget->iconButton->icon());
TQString pluginName = newPlugin->pluginName();
m_plugins.insert(pluginName, newPlugin);
emit pluginsChanged();
}
delete configDlg;
}
void QuantaPluginEditor::addSearchPath()
{
// Get a dir and append it to the line edit
TQString appendDir = KFileDialog::getExistingDirectory(TQString::null, 0, i18n("Select Folder"));
if(!appendDir.isNull())
{
m_pluginEditorWidget->searchPaths->setText(m_pluginEditorWidget->searchPaths->text()+appendDir+":");
}
}
void QuantaPluginEditor::configurePlugin()
{
// create a new config dialog. populate with plugin data
TQString key;
TQListViewItem *item = m_pluginEditorWidget->pluginList->currentItem();
if(item)
key = item->text(0);
if(!key.isNull() && m_plugins.find(key))
{
QuantaPluginConfig *configDlg = new QuantaPluginConfig(this, "pluginConfig");
QuantaPlugin *curPlugin = m_plugins.find(key);
PluginConfig *configWidget = static_cast<PluginConfig*>(configDlg->mainWidget());
configWidget->outputWindow->setCurrentText(curPlugin->outputWindow());
configWidget->pluginName->setText(curPlugin->pluginName());
configWidget->pluginFileName->setText(curPlugin->fileName());
configWidget->location->setText(curPlugin->location());
configWidget->iconButton->setIcon(curPlugin->icon());
configWidget->inputBox->setCurrentItem(curPlugin->input());
configWidget->readOnlyBox->setChecked(curPlugin->readOnlyPart());
if(configDlg->exec())
{
curPlugin->setPluginName(configWidget->pluginName->text());
curPlugin->setFileName(configWidget->pluginFileName->text());
curPlugin->setLocation(configWidget->location->text());
curPlugin->setOutputWindow(configWidget->outputWindow->currentText());
curPlugin->setIcon(configWidget->iconButton->icon());
curPlugin->setInput(configWidget->inputBox->currentItem());
curPlugin->setReadOnlyPart(configWidget->readOnlyBox->isChecked());
}
delete configDlg;
emit pluginsChanged();
}
}
void QuantaPluginEditor::configurePlugin(TQListViewItem* item, const TQPoint&, int)
{
if (item)
configurePlugin();
}
void QuantaPluginEditor::refreshPlugins()
{
// call validate on all plugins to refresh their status
m_pluginEditorWidget->pluginList->clear();
TQDictIterator<QuantaPlugin> it(m_plugins);
for(;it.current();++it)
{
TQListViewItem *newItem = new PluginEditorItem(m_pluginEditorWidget->pluginList);
QuantaPlugin *curPlugin = it.current();
newItem->setText(0, curPlugin->pluginName());
TQPixmap statusIcon;
bool isValid = QuantaPlugin::validatePlugin(curPlugin);
if(isValid)
statusIcon = SmallIcon("ok", KGlobal::instance());
else
statusIcon = SmallIcon("no", KGlobal::instance());
newItem->setPixmap(1, statusIcon);
newItem->setText(2, curPlugin->location());
newItem->setText(3, curPlugin->fileName());
newItem->setText(4, curPlugin->outputWindow());
m_pluginEditorWidget->pluginList->insertItem(newItem);
}
}
void QuantaPluginEditor::removePlugin()
{
TQListViewItem *currentItem = m_pluginEditorWidget->pluginList->currentItem();
if (currentItem)
{
QuantaPlugin *plugin = m_plugins.find(currentItem->text(0));
if(plugin)
{
m_plugins.remove(plugin->pluginName());
delete plugin;
emit pluginsChanged();
}
}
}
void QuantaPluginEditor::setPlugins(TQDict<QuantaPlugin> a_plugins)
{
m_plugins = a_plugins;
emit pluginsChanged();
}
PluginEditorItem::PluginEditorItem(TQListView *a_parent)
: TQListViewItem(a_parent)
{
}
void PluginEditorItem::paintCell(TQPainter *a_painter, const TQColorGroup &a_cg, int a_column, int a_width, int a_align)
{
/*
if(a_column == 2)
a_align = Qt::AlignCenter;
FIXME : Why won't QT let us align cell contents?
*/
TQListViewItem::paintCell(a_painter, a_cg, a_column, a_width, a_align);
}
/** No descriptions */
void QuantaPluginEditor::setSearchPaths(const TQStringList& paths)
{
TQString str;
for (uint i =0; i < paths.count(); i++)
{
str += paths[i] +":";
}
m_pluginEditorWidget->searchPaths->setText(str);
}
/** No descriptions */
TQStringList QuantaPluginEditor::searchPathList()
{
TQString str = m_pluginEditorWidget->searchPaths->text();
TQStringList paths = TQStringList::split(":",str);
return paths;
}
#include "quantaplugineditor.moc"
|