KDevelop API Documentation

parts/tools/toolsconfig.cpp

Go to the documentation of this file.
00001 #include "toolsconfig.h" 00002 00003 #include <qapplication.h> 00004 #include <qlabel.h> 00005 #include <qlayout.h> 00006 #include <qlistbox.h> 00007 #include <qpushbutton.h> 00008 #include <qheader.h> 00009 00010 #include <kapplication.h> 00011 #include <kdesktopfile.h> 00012 #include <kdialog.h> 00013 #include <kiconloader.h> 00014 #include <klocale.h> 00015 00016 #include "tools_part.h" 00017 #include "kapplicationtree.h" 00018 00019 00020 ToolsConfig::ToolsConfig(QWidget *parent, const char *name) 00021 : QWidget(parent, name), _tree(0) 00022 { 00023 _entries.setAutoDelete(true); 00024 } 00025 00026 00027 void ToolsConfig::showEvent(QShowEvent *e) 00028 { 00029 QWidget::showEvent(e); 00030 00031 if (!_tree) 00032 { 00033 QApplication::setOverrideCursor(Qt::waitCursor); 00034 00035 QHBoxLayout *hbox = new QHBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint()); 00036 00037 QVBoxLayout *vbox = new QVBoxLayout(hbox); 00038 _tree = new KDevApplicationTree(this); 00039 _tree->header()->hide(); 00040 QLabel *l = new QLabel(_tree, i18n("&Applications:"), this); 00041 l->show(); 00042 _tree->show(); 00043 00044 vbox->addWidget(l); 00045 vbox->addWidget(_tree); 00046 00047 vbox = new QVBoxLayout(hbox); 00048 00049 _toList = new QPushButton(QApplication::reverseLayout() ? "<<" : ">>", this); 00050 _toList->show(); 00051 vbox->addWidget(_toList); 00052 00053 connect(_toList, SIGNAL(clicked()), this, SLOT(toList())); 00054 00055 _toTree = new QPushButton(QApplication::reverseLayout() ? ">>" : "<<", this); 00056 _toTree->show(); 00057 vbox->addWidget(_toTree); 00058 00059 connect(_toTree, SIGNAL(clicked()), this, SLOT(toTree())); 00060 00061 vbox = new QVBoxLayout(hbox); 00062 _list = new QListBox(this); 00063 l = new QLabel(_list, i18n("&Tools menu:"), this); 00064 l->show(); 00065 _list->show(); 00066 vbox->addWidget(l); 00067 vbox->addWidget(_list); 00068 00069 QApplication::restoreOverrideCursor(); 00070 } 00071 00072 fill(); 00073 checkButtons(); 00074 00075 connect(_tree, SIGNAL(selectionChanged()), this, SLOT(checkButtons())); 00076 connect(_list, SIGNAL(selectionChanged()), this, SLOT(checkButtons())); 00077 } 00078 00079 00080 void ToolsConfig::checkButtons() 00081 { 00082 _toList->setEnabled(_tree->selectedItem() && !_tree->selectedItem()->firstChild()); 00083 _toTree->setEnabled(_list->currentItem() >= 0 && _list->currentItem() < (int)_list->count()); 00084 } 00085 00086 00087 void ToolsConfig::fill() 00088 { 00089 _entries.clear(); 00090 00091 KConfig *config = ToolsFactory::instance()->config(); 00092 config->setGroup("Tools"); 00093 00094 QStringList list = config->readListEntry("Tools"); 00095 00096 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) 00097 add(*it); 00098 } 00099 00100 00101 void ToolsConfig::add(const QString &desktopFile) 00102 { 00103 KDesktopFile df(desktopFile, true); 00104 if (df.readName().isEmpty()) 00105 return; 00106 00107 Entry *entry = new Entry; 00108 00109 if (!df.readIcon().isEmpty()) 00110 entry->icon = BarIcon(df.readIcon()); 00111 entry->name = df.readName(); 00112 entry->desktopFile = desktopFile; 00113 00114 _entries.append(entry); 00115 00116 updateList(); 00117 00118 checkButtons(); 00119 } 00120 00121 00122 void ToolsConfig::toList() 00123 { 00124 KDevAppTreeListItem *item = dynamic_cast<KDevAppTreeListItem*>(_tree->selectedItem()); 00125 if (item && !item->desktopEntryPath().isEmpty()) 00126 add(item->desktopEntryPath()); 00127 checkButtons(); 00128 } 00129 00130 00131 void ToolsConfig::toTree() 00132 { 00133 _entries.remove(_list->currentItem()); 00134 updateList(); 00135 checkButtons(); 00136 } 00137 00138 00139 void ToolsConfig::accept() 00140 { 00141 KConfig *config = ToolsFactory::instance()->config(); 00142 config->setGroup("Tools"); 00143 00144 QStringList l; 00145 QPtrListIterator<Entry> it(_entries); 00146 for ( ; it.current(); ++it) 00147 l.append(it.current()->desktopFile); 00148 00149 config->writeEntry("Tools", l); 00150 config->sync(); 00151 } 00152 00153 00154 void ToolsConfig::updateList() 00155 { 00156 _list->setUpdatesEnabled(false); 00157 00158 _list->clear(); 00159 00160 QPtrListIterator<Entry> it(_entries); 00161 for ( ; it.current(); ++it) 00162 _list->insertItem(it.current()->icon, it.current()->name); 00163 00164 _list->setUpdatesEnabled(true); 00165 _list->repaint(); 00166 } 00167 00168 00169 #include "toolsconfig.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 6 17:39:13 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003