KDevelop API Documentation

parts/tools/kapplicationtree.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Nicked from KDElibs since KDevApplicationTree is not a public class.. 00003 00004 Copyright (C) 1997 Torben Weis <weis@stud.uni-frankfurt.de> 00005 Copyright (C) 1999 Dirk A. Mueller <dmuell@gmx.net> 00006 Portions copyright (C) 1999 Preston Brown <pbrown@kde.org> 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Library General Public 00010 License as published by the Free Software Foundation; either 00011 version 2 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Library General Public License for more details. 00017 00018 You should have received a copy of the GNU Library General Public License 00019 along with this library; see the file COPYING.LIB. If not, write to 00020 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00021 Boston, MA 02111-1307, USA. 00022 */ 00023 00024 #include <qfile.h> 00025 #include <qdir.h> 00026 #include <qdialog.h> 00027 #include <qpixmap.h> 00028 #include <qlabel.h> 00029 #include <qlayout.h> 00030 #include <qpushbutton.h> 00031 #include <qtoolbutton.h> 00032 #include <qcheckbox.h> 00033 #include <qtooltip.h> 00034 #include <qstyle.h> 00035 00036 #include <kapplication.h> 00037 #include <kbuttonbox.h> 00038 #include <kcombobox.h> 00039 #include <kdesktopfile.h> 00040 #include <kdialog.h> 00041 #include <kglobal.h> 00042 #include <klineedit.h> 00043 #include <klocale.h> 00044 #include <kiconloader.h> 00045 #include <kmimemagic.h> 00046 #include <krun.h> 00047 #include <kstandarddirs.h> 00048 #include <kstringhandler.h> 00049 #include <kuserprofile.h> 00050 #include <kurlcompletion.h> 00051 #include <kurlrequester.h> 00052 #include <dcopclient.h> 00053 #include <kmimetype.h> 00054 #include <kservicegroup.h> 00055 #include <klistview.h> 00056 #include <ksycoca.h> 00057 #include <kdebug.h> 00058 00059 #include "kapplicationtree.h" 00060 00061 template class QPtrList<QString>; 00062 00063 #define SORT_SPEC (QDir::DirsFirst | QDir::Name | QDir::IgnoreCase) 00064 00065 00066 // ---------------------------------------------------------------------- 00067 00068 KDevAppTreeListItem::KDevAppTreeListItem( KListView* parent, const QString & name, 00069 const QPixmap& pixmap, bool parse, bool dir, const QString& p, const QString& c, const QString& dE ) 00070 : QListViewItem( parent, name ) 00071 { 00072 init(pixmap, parse, dir, p, c, dE); 00073 } 00074 00075 00076 // ---------------------------------------------------------------------- 00077 00078 KDevAppTreeListItem::KDevAppTreeListItem( QListViewItem* parent, const QString & name, 00079 const QPixmap& pixmap, bool parse, bool dir, const QString& p, const QString& c, const QString& dE ) 00080 : QListViewItem( parent, name ) 00081 { 00082 init(pixmap, parse, dir, p, c, dE); 00083 } 00084 00085 00086 // ---------------------------------------------------------------------- 00087 00088 void KDevAppTreeListItem::init(const QPixmap& pixmap, bool parse, bool dir, const QString& _path, const QString& _exec, const QString& _dEntry) 00089 { 00090 setPixmap(0, pixmap); 00091 parsed = parse; 00092 directory = dir; 00093 path = _path; // relative path 00094 exec = _exec; 00095 dEntry = _dEntry; 00096 exec.simplifyWhiteSpace(); 00097 exec.truncate(exec.find(' ')); 00098 } 00099 00100 00101 // ---------------------------------------------------------------------- 00102 // Ensure that dirs are sorted in front of files and case is ignored 00103 00104 QString KDevAppTreeListItem::key(int column, bool /*ascending*/) const 00105 { 00106 if (directory) 00107 return QString::fromLatin1(" ") + text(column).upper(); 00108 else 00109 return text(column).upper(); 00110 } 00111 00112 void KDevAppTreeListItem::activate() 00113 { 00114 if ( directory ) 00115 setOpen(!isOpen()); 00116 } 00117 00118 void KDevAppTreeListItem::setOpen( bool o ) 00119 { 00120 if( o && !parsed ) { // fill the children before opening 00121 ((KDevApplicationTree *) parent())->addDesktopGroup( path, this ); 00122 parsed = true; 00123 } 00124 QListViewItem::setOpen( o ); 00125 } 00126 00127 bool KDevAppTreeListItem::isDirectory() 00128 { 00129 return directory; 00130 } 00131 00132 // ---------------------------------------------------------------------- 00133 00134 KDevApplicationTree::KDevApplicationTree( QWidget *parent, const char* name ) 00135 : KListView( parent, name ), currentitem(0) 00136 { 00137 addColumn( i18n("Known Applications") ); 00138 setRootIsDecorated( true ); 00139 00140 addDesktopGroup( QString::null ); 00141 00142 connect( this, SIGNAL( currentChanged(QListViewItem*) ), SLOT( slotItemHighlighted(QListViewItem*) ) ); 00143 connect( this, SIGNAL( selectionChanged(QListViewItem*) ), SLOT( slotSelectionChanged(QListViewItem*) ) ); 00144 } 00145 00146 // ---------------------------------------------------------------------- 00147 00148 bool KDevApplicationTree::isDirSel() 00149 { 00150 if (!currentitem) return false; // if currentitem isn't set 00151 return currentitem->isDirectory(); 00152 } 00153 00154 // ---------------------------------------------------------------------- 00155 00156 void KDevApplicationTree::addDesktopGroup( QString relPath, KDevAppTreeListItem *item) 00157 { 00158 KServiceGroup::Ptr root = KServiceGroup::group(relPath); 00159 KServiceGroup::List list = root->entries(); 00160 00161 KDevAppTreeListItem * newItem; 00162 for( KServiceGroup::List::ConstIterator it = list.begin(); 00163 it != list.end(); it++) 00164 { 00165 QString icon; 00166 QString text; 00167 QString relPath; 00168 QString exec; 00169 QString dEntry; 00170 bool isDir = false; 00171 KSycocaEntry *p = (*it); 00172 if (p->isType(KST_KService)) 00173 { 00174 KService *service = static_cast<KService *>(p); 00175 icon = service->icon(); 00176 text = service->name(); 00177 exec = service->exec(); 00178 dEntry = service->desktopEntryPath(); 00179 } 00180 else if (p->isType(KST_KServiceGroup)) 00181 { 00182 KServiceGroup *serviceGroup = static_cast<KServiceGroup *>(p); 00183 icon = serviceGroup->icon(); 00184 text = serviceGroup->caption(); 00185 relPath = serviceGroup->relPath(); 00186 isDir = true; 00187 if ( text[0] == '.' ) // skip ".hidden" like kicker does 00188 continue; 00189 // avoid adding empty groups 00190 KServiceGroup::Ptr subMenuRoot = KServiceGroup::group(relPath); 00191 if (subMenuRoot->childCount() == 0) 00192 continue; 00193 } 00194 else 00195 { 00196 kdWarning(250) << "KServiceGroup: Unexpected object in list!" << endl; 00197 continue; 00198 } 00199 00200 QPixmap pixmap = SmallIcon( icon ); 00201 00202 if (item) 00203 newItem = new KDevAppTreeListItem( item, text, pixmap, false, isDir, 00204 relPath, exec, dEntry ); 00205 else 00206 newItem = new KDevAppTreeListItem( this, text, pixmap, false, isDir, 00207 relPath, exec, dEntry ); 00208 if (isDir) 00209 newItem->setExpandable( true ); 00210 } 00211 } 00212 00213 00214 // ---------------------------------------------------------------------- 00215 00216 void KDevApplicationTree::slotItemHighlighted(QListViewItem* i) 00217 { 00218 // i may be 0 (see documentation) 00219 if(!i) 00220 return; 00221 00222 KDevAppTreeListItem *item = (KDevAppTreeListItem *) i; 00223 00224 currentitem = item; 00225 00226 if( (!item->directory ) && (!item->exec.isEmpty()) ) 00227 emit highlighted( item->text(0), item->exec ); 00228 } 00229 00230 00231 // ---------------------------------------------------------------------- 00232 00233 void KDevApplicationTree::slotSelectionChanged(QListViewItem* i) 00234 { 00235 // i may be 0 (see documentation) 00236 if(!i) 00237 return; 00238 00239 KDevAppTreeListItem *item = (KDevAppTreeListItem *) i; 00240 00241 currentitem = item; 00242 00243 if( ( !item->directory ) && (!item->exec.isEmpty() ) ) 00244 emit selected( item->text(0), item->exec ); 00245 } 00246 00247 // ---------------------------------------------------------------------- 00248 00249 void KDevApplicationTree::resizeEvent( QResizeEvent * e) 00250 { 00251 setColumnWidth(0, width()-QApplication::style().pixelMetric(QStyle::PM_ScrollBarExtent)); 00252 KListView::resizeEvent(e); 00253 } 00254 00255 00256 00257 #include "kapplicationtree.moc" 00258
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