• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

interfaces

editorchooser.cpp

Go to the documentation of this file.
00001 #include <editorchooser.h>
00002 #include <editorchooser.moc>
00003 
00004 #include <qcombobox.h>
00005 #include <ktrader.h>
00006 #include <kconfig.h>
00007 #include <qstringlist.h>
00008 #include <kservice.h>
00009 #include <klocale.h>
00010 #include <qlabel.h>
00011 #include <kapplication.h>
00012 #include <qlayout.h>
00013 
00014 #include "editorchooser_ui.h"
00015 
00016 using namespace KTextEditor;
00017 
00018 namespace KTextEditor
00019 {
00020   class PrivateEditorChooser
00021   {
00022   public:
00023     PrivateEditorChooser()
00024     {
00025     }
00026     ~PrivateEditorChooser(){}
00027   // Data Members
00028   EditorChooser_UI *chooser;
00029   QStringList ElementNames;
00030   QStringList elements;
00031   };
00032 
00033 }
00034 
00035 EditorChooser::EditorChooser(QWidget *parent,const char *name) :
00036     QWidget (parent,name)
00037   {
00038   d = new PrivateEditorChooser ();
00039 
00040   // sizemanagment
00041   QGridLayout *grid = new QGridLayout( this, 1, 1 );
00042 
00043 
00044   d->chooser = new EditorChooser_UI (this, name);
00045 
00046   grid->addWidget( d->chooser, 0, 0);
00047 
00048 
00049     KTrader::OfferList offers = KTrader::self()->query("text/plain", "'KTextEditor/Document' in ServiceTypes");
00050     KConfig *config=new KConfig("default_components");
00051     config->setGroup("KTextEditor");
00052     QString editor = config->readPathEntry("embeddedEditor");
00053 
00054         if (editor.isEmpty()) editor="katepart";
00055 
00056     for (KTrader::OfferList::Iterator it = offers.begin(); it != offers.end(); ++it)
00057     {
00058             if ((*it)->desktopEntryName().contains(editor))
00059         {
00060             d->chooser->editorCombo->insertItem(i18n("System Default (%1)").arg((*it)->name()));
00061             break;
00062         }
00063     }
00064 
00065     for (KTrader::OfferList::Iterator it = offers.begin(); it != offers.end(); ++it)
00066     {
00067             d->chooser->editorCombo->insertItem((*it)->name());
00068         d->elements.append((*it)->desktopEntryName());
00069     }
00070         d->chooser->editorCombo->setCurrentItem(0);
00071 }
00072 
00073 EditorChooser:: ~EditorChooser(){
00074   delete d;
00075 }
00076 
00077 void EditorChooser::readAppSetting(const QString& postfix){
00078     KConfig *cfg=kapp->config();
00079     QString previousGroup=cfg->group();
00080     cfg->setGroup("KTEXTEDITOR:"+postfix);
00081     QString editor=cfg->readPathEntry("editor");
00082     if (editor.isEmpty()) d->chooser->editorCombo->setCurrentItem(0);
00083     else
00084     {
00085         int idx=d->elements.findIndex(editor);
00086         idx=idx+1;
00087         d->chooser->editorCombo->setCurrentItem(idx);
00088     }
00089     cfg->setGroup(previousGroup);
00090 }
00091 
00092 void EditorChooser::writeAppSetting(const QString& postfix){
00093     KConfig *cfg=kapp->config();
00094     QString previousGroup=cfg->group();
00095     cfg->setGroup("KTEXTEDITOR:"+postfix);
00096     cfg->writeEntry("DEVELOPER_INFO","NEVER TRY TO USE VALUES FROM THAT GROUP, THEY ARE SUBJECT TO CHANGES");
00097     cfg->writePathEntry("editor", (d->chooser->editorCombo->currentItem()==0) ? 
00098         QString::null : (*d->elements.at(d->chooser->editorCombo->currentItem()-1)));
00099     cfg->sync();
00100     cfg->setGroup(previousGroup);
00101 
00102 }
00103 
00104 KTextEditor::Document *EditorChooser::createDocument(QObject *parent,const char* name, const QString& postfix,bool fallBackToKatePart){
00105 
00106     KTextEditor::Document *tmpDoc=0;
00107 
00108     KConfig *cfg=kapp->config();
00109         QString previousGroup=cfg->group();
00110         cfg->setGroup("KTEXTEDITOR:"+postfix);
00111         QString editor=cfg->readPathEntry("editor");
00112     cfg->setGroup(previousGroup);
00113     if (editor.isEmpty())
00114     {
00115         KConfig *config=new KConfig("default_components");
00116         config->setGroup("KTextEditor");
00117         editor = config->readPathEntry("embeddedEditor", "katepart");
00118         delete config;
00119     }
00120 
00121     KService::Ptr serv=KService::serviceByDesktopName(editor);
00122     if (serv)
00123     {
00124         tmpDoc=KTextEditor::createDocument(serv->library().latin1(),parent,name);
00125         if (tmpDoc) return tmpDoc;
00126     }
00127     if (fallBackToKatePart)
00128         return KTextEditor::createDocument("libkatepart",parent,name);
00129 
00130     return 0;
00131 }
00132 
00133 KTextEditor::Editor *EditorChooser::createEditor(QWidget *parentWidget,QObject *parent,const char* widgetName,
00134     const char* name,const QString& postfix,bool fallBackToKatePart){
00135 
00136         KTextEditor::Editor *tmpEd=0;
00137 
00138         KConfig *cfg=kapp->config();
00139         QString previousGroup=cfg->group();
00140         cfg->setGroup("KTEXTEDITOR:"+postfix);
00141         QString editor=cfg->readPathEntry("editor");
00142         cfg->setGroup(previousGroup);
00143         if (editor.isEmpty())
00144         {
00145                 KConfig *config=new KConfig("default_components");
00146                 config->setGroup("KTextEditor");
00147                 editor = config->readPathEntry("embeddedEditor", "katepart");
00148                 delete config;
00149         }
00150 
00151         KService::Ptr serv=KService::serviceByDesktopName(editor);
00152         if (serv)
00153         {
00154                 tmpEd=KTextEditor::createEditor(serv->library().latin1(),parentWidget,widgetName,parent,name);
00155                 if (tmpEd) return tmpEd;
00156         }
00157         if (fallBackToKatePart)
00158                 return KTextEditor::createEditor("libkatepart",parentWidget,widgetName,parent,name);
00159 
00160         return 0;
00161 }
00162 

interfaces

Skip menu "interfaces"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal