KDevelop API Documentation

editors/editor-chooser/editorchooser_widget.cpp

Go to the documentation of this file.
00001 #include <qcombobox.h> 00002 00003 00004 #include <kapplication.h> 00005 #include <kdeversion.h> 00006 #include <ktrader.h> 00007 #include <kservice.h> 00008 #include <kdebug.h> 00009 #include <kconfig.h> 00010 00011 00012 #include "editorchooser_widget.h" 00013 00014 00015 EditorChooserWidget::EditorChooserWidget(QWidget *parent, const char *name) 00016 : EditChooser(parent, name) 00017 { 00018 load(); 00019 } 00020 00021 00022 void EditorChooserWidget::load() 00023 { 00024 EditorPart->clear(); 00025 00026 // ask the trader which editors he has to offer 00027 KTrader::OfferList offers = KTrader::self()->query("text/plain", "'KTextEditor/Document' in ServiceTypes"); 00028 00029 // find the editor to use 00030 KConfig *config = kapp->config(); 00031 config->setGroup("Editor"); 00032 QString editor = config->readPathEntry("EmbeddedKTextEditor"); 00033 00034 // add the entries to the listview 00035 KTrader::OfferList::Iterator it; 00036 int index=-1, current=0; 00037 for (it = offers.begin(); it != offers.end(); ++it) 00038 { 00039 EditorPart->insertItem((*it)->name()); 00040 if ( (*it)->name() == editor ) 00041 index = current; 00042 ++current; 00043 } 00044 00045 if (index >=0) 00046 EditorPart->setCurrentItem(index); 00047 } 00048 00049 00050 void EditorChooserWidget::save() 00051 { 00052 KConfig *config = kapp->config(); 00053 config->setGroup("Editor"); 00054 00055 KTrader::OfferList offers = KTrader::self()->query("text/plain", "'KTextEditor/Document' in ServiceTypes"); 00056 00057 KTrader::OfferList::Iterator it; 00058 for (it = offers.begin(); it != offers.end(); ++it) 00059 if ( EditorPart->currentText() == (*it)->name() ) { 00060 #if defined(KDE_IS_VERSION) 00061 # if KDE_IS_VERSION(3,1,3) 00062 # ifndef _KDE_3_1_3_ 00063 # define _KDE_3_1_3_ 00064 # endif 00065 # endif 00066 #endif 00067 #if defined(_KDE_3_1_3_) 00068 config->writePathEntry("EmbeddedKTextEditor", (*it)->name()); 00069 #else 00070 config->writeEntry("EmbeddedKTextEditor", (*it)->name()); 00071 #endif 00072 } 00073 00074 config->sync(); 00075 } 00076 00077 00078 void EditorChooserWidget::accept() 00079 { 00080 save(); 00081 } 00082 00083 00084 #include "editorchooser_widget.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:38:55 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003