diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 114a878c64ce6f8223cfd22d76a20eb16d177e5e (patch) | |
tree | acaf47eb0fa12142d3896416a69e74cbf5a72242 /parts/tools/toolsconfig.cpp | |
download | tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.tar.gz tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'parts/tools/toolsconfig.cpp')
-rw-r--r-- | parts/tools/toolsconfig.cpp | 169 |
1 files changed, 169 insertions, 0 deletions
diff --git a/parts/tools/toolsconfig.cpp b/parts/tools/toolsconfig.cpp new file mode 100644 index 00000000..523fe388 --- /dev/null +++ b/parts/tools/toolsconfig.cpp @@ -0,0 +1,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" |