• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • interfaces
 

interfaces

  • interfaces
  • ktexteditor
editorchooser.cpp
1 #include <editorchooser.h>
2 #include <editorchooser.moc>
3 
4 #include <tqcombobox.h>
5 #include <ktrader.h>
6 #include <kconfig.h>
7 #include <tqstringlist.h>
8 #include <kservice.h>
9 #include <klocale.h>
10 #include <tqlabel.h>
11 #include <kapplication.h>
12 #include <tqlayout.h>
13 
14 #include "editorchooser_ui.h"
15 
16 using namespace KTextEditor;
17 
18 namespace KTextEditor
19 {
20  class PrivateEditorChooser
21  {
22  public:
23  PrivateEditorChooser()
24  {
25  }
26  ~PrivateEditorChooser(){}
27  // Data Members
28  EditorChooser_UI *chooser;
29  TQStringList ElementNames;
30  TQStringList elements;
31  };
32 
33 }
34 
35 EditorChooser::EditorChooser(TQWidget *parent,const char *name) :
36  TQWidget (parent,name)
37  {
38  d = new PrivateEditorChooser ();
39 
40  // sizemanagment
41  TQGridLayout *grid = new TQGridLayout( this, 1, 1 );
42 
43 
44  d->chooser = new EditorChooser_UI (this, name);
45 
46  grid->addWidget( d->chooser, 0, 0);
47 
48 
49  KTrader::OfferList offers = KTrader::self()->query("text/plain", "'KTextEditor/Document' in ServiceTypes");
50  KConfig *config=new KConfig("default_components");
51  config->setGroup("KTextEditor");
52  TQString editor = config->readPathEntry("embeddedEditor");
53 
54  if (editor.isEmpty()) editor="katepart";
55 
56  for (KTrader::OfferList::Iterator it = offers.begin(); it != offers.end(); ++it)
57  {
58  if ((*it)->desktopEntryName().contains(editor))
59  {
60  d->chooser->editorCombo->insertItem(TQString(i18n("System Default (%1)").arg((*it)->name())));
61  break;
62  }
63  }
64 
65  for (KTrader::OfferList::Iterator it = offers.begin(); it != offers.end(); ++it)
66  {
67  d->chooser->editorCombo->insertItem((*it)->name());
68  d->elements.append((*it)->desktopEntryName());
69  }
70  d->chooser->editorCombo->setCurrentItem(0);
71 }
72 
73 EditorChooser:: ~EditorChooser(){
74  delete d;
75 }
76 
77 void EditorChooser::readAppSetting(const TQString& postfix){
78  KConfig *cfg=kapp->config();
79  TQString previousGroup=cfg->group();
80  cfg->setGroup("KTEXTEDITOR:"+postfix);
81  TQString editor=cfg->readPathEntry("editor");
82  if (editor.isEmpty()) d->chooser->editorCombo->setCurrentItem(0);
83  else
84  {
85  int idx=d->elements.findIndex(editor);
86  idx=idx+1;
87  d->chooser->editorCombo->setCurrentItem(idx);
88  }
89  cfg->setGroup(previousGroup);
90 }
91 
92 void EditorChooser::writeAppSetting(const TQString& postfix){
93  KConfig *cfg=kapp->config();
94  TQString previousGroup=cfg->group();
95  cfg->setGroup("KTEXTEDITOR:"+postfix);
96  cfg->writeEntry("DEVELOPER_INFO","NEVER TRY TO USE VALUES FROM THAT GROUP, THEY ARE SUBJECT TO CHANGES");
97  cfg->writePathEntry("editor", (d->chooser->editorCombo->currentItem()==0) ?
98  TQString::null : (*d->elements.at(d->chooser->editorCombo->currentItem()-1)));
99  cfg->sync();
100  cfg->setGroup(previousGroup);
101 
102 }
103 
104 KTextEditor::Document *EditorChooser::createDocument(TQObject *parent,const char* name, const TQString& postfix,bool fallBackToKatePart){
105 
106  KTextEditor::Document *tmpDoc=0;
107 
108  KConfig *cfg=kapp->config();
109  TQString previousGroup=cfg->group();
110  cfg->setGroup("KTEXTEDITOR:"+postfix);
111  TQString editor=cfg->readPathEntry("editor");
112  cfg->setGroup(previousGroup);
113  if (editor.isEmpty())
114  {
115  KConfig *config=new KConfig("default_components");
116  config->setGroup("KTextEditor");
117  editor = config->readPathEntry("embeddedEditor", "katepart");
118  delete config;
119  }
120 
121  KService::Ptr serv=KService::serviceByDesktopName(editor);
122  if (serv)
123  {
124  tmpDoc=KTextEditor::createDocument(serv->library().latin1(),parent,name);
125  if (tmpDoc) return tmpDoc;
126  }
127  if (fallBackToKatePart)
128  return KTextEditor::createDocument("libkatepart",parent,name);
129 
130  return 0;
131 }
132 
133 KTextEditor::Editor *EditorChooser::createEditor(TQWidget *parentWidget,TQObject *parent,const char* widgetName,
134  const char* name,const TQString& postfix,bool fallBackToKatePart){
135 
136  KTextEditor::Editor *tmpEd=0;
137 
138  KConfig *cfg=kapp->config();
139  TQString previousGroup=cfg->group();
140  cfg->setGroup("KTEXTEDITOR:"+postfix);
141  TQString editor=cfg->readPathEntry("editor");
142  cfg->setGroup(previousGroup);
143  if (editor.isEmpty())
144  {
145  KConfig *config=new KConfig("default_components");
146  config->setGroup("KTextEditor");
147  editor = config->readPathEntry("embeddedEditor", "katepart");
148  delete config;
149  }
150 
151  KService::Ptr serv=KService::serviceByDesktopName(editor);
152  if (serv)
153  {
154  tmpEd=KTextEditor::createEditor(serv->library().latin1(),parentWidget,widgetName,parent,name);
155  if (tmpEd) return tmpEd;
156  }
157  if (fallBackToKatePart)
158  return KTextEditor::createEditor("libkatepart",parentWidget,widgetName,parent,name);
159 
160  return 0;
161 }
162 
KConfig::writeEntry
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
KConfig::sync
virtual void sync()
klocale.h
KConfig::setGroup
void setGroup(const TQString &group)
KConfig::readPathEntry
TQString readPathEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
KConfig::group
TQString group() const
KTextEditor::Document
The main class representing a text document.
Definition: document.h:31
KTextEditor
KTextEditor is KDE's standard text editing KPart interface.
Definition: blockselectiondcopinterface.h:9
KConfig
KTextEditor::Editor
This is a simplfied version of the Document & View classes Usage: Load it, merge it's gui + be happy Exte...
Definition: editor.h:39
KConfig::writePathEntry
void writePathEntry(const TQString &pKey, const TQString &path, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)

interfaces

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

interfaces

Skip menu "interfaces"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for interfaces by doxygen 1.8.8
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |