summaryrefslogtreecommitdiffstats
path: root/interfaces/ktexteditor/editorchooser.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch)
tree5ac38a06f3dde268dc7927dc155896926aaf7012 /interfaces/ktexteditor/editorchooser.cpp
downloadtdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz
tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'interfaces/ktexteditor/editorchooser.cpp')
-rw-r--r--interfaces/ktexteditor/editorchooser.cpp162
1 files changed, 162 insertions, 0 deletions
diff --git a/interfaces/ktexteditor/editorchooser.cpp b/interfaces/ktexteditor/editorchooser.cpp
new file mode 100644
index 000000000..a7211ab49
--- /dev/null
+++ b/interfaces/ktexteditor/editorchooser.cpp
@@ -0,0 +1,162 @@
+#include <editorchooser.h>
+#include <editorchooser.moc>
+
+#include <qcombobox.h>
+#include <ktrader.h>
+#include <kconfig.h>
+#include <qstringlist.h>
+#include <kservice.h>
+#include <klocale.h>
+#include <qlabel.h>
+#include <kapplication.h>
+#include <qlayout.h>
+
+#include "editorchooser_ui.h"
+
+using namespace KTextEditor;
+
+namespace KTextEditor
+{
+ class PrivateEditorChooser
+ {
+ public:
+ PrivateEditorChooser()
+ {
+ }
+ ~PrivateEditorChooser(){}
+ // Data Members
+ EditorChooser_UI *chooser;
+ QStringList ElementNames;
+ QStringList elements;
+ };
+
+}
+
+EditorChooser::EditorChooser(QWidget *parent,const char *name) :
+ QWidget (parent,name)
+ {
+ d = new PrivateEditorChooser ();
+
+ // sizemanagment
+ QGridLayout *grid = new QGridLayout( this, 1, 1 );
+
+
+ d->chooser = new EditorChooser_UI (this, name);
+
+ grid->addWidget( d->chooser, 0, 0);
+
+
+ KTrader::OfferList offers = KTrader::self()->query("text/plain", "'KTextEditor/Document' in ServiceTypes");
+ KConfig *config=new KConfig("default_components");
+ config->setGroup("KTextEditor");
+ QString editor = config->readPathEntry("embeddedEditor");
+
+ if (editor.isEmpty()) editor="katepart";
+
+ for (KTrader::OfferList::Iterator it = offers.begin(); it != offers.end(); ++it)
+ {
+ if ((*it)->desktopEntryName().contains(editor))
+ {
+ d->chooser->editorCombo->insertItem(i18n("System Default (%1)").arg((*it)->name()));
+ break;
+ }
+ }
+
+ for (KTrader::OfferList::Iterator it = offers.begin(); it != offers.end(); ++it)
+ {
+ d->chooser->editorCombo->insertItem((*it)->name());
+ d->elements.append((*it)->desktopEntryName());
+ }
+ d->chooser->editorCombo->setCurrentItem(0);
+}
+
+EditorChooser:: ~EditorChooser(){
+ delete d;
+}
+
+void EditorChooser::readAppSetting(const QString& postfix){
+ KConfig *cfg=kapp->config();
+ QString previousGroup=cfg->group();
+ cfg->setGroup("KTEXTEDITOR:"+postfix);
+ QString editor=cfg->readPathEntry("editor");
+ if (editor.isEmpty()) d->chooser->editorCombo->setCurrentItem(0);
+ else
+ {
+ int idx=d->elements.findIndex(editor);
+ idx=idx+1;
+ d->chooser->editorCombo->setCurrentItem(idx);
+ }
+ cfg->setGroup(previousGroup);
+}
+
+void EditorChooser::writeAppSetting(const QString& postfix){
+ KConfig *cfg=kapp->config();
+ QString previousGroup=cfg->group();
+ cfg->setGroup("KTEXTEDITOR:"+postfix);
+ cfg->writeEntry("DEVELOPER_INFO","NEVER TRY TO USE VALUES FROM THAT GROUP, THEY ARE SUBJECT TO CHANGES");
+ cfg->writePathEntry("editor", (d->chooser->editorCombo->currentItem()==0) ?
+ QString::null : (*d->elements.at(d->chooser->editorCombo->currentItem()-1)));
+ cfg->sync();
+ cfg->setGroup(previousGroup);
+
+}
+
+KTextEditor::Document *EditorChooser::createDocument(QObject *parent,const char* name, const QString& postfix,bool fallBackToKatePart){
+
+ KTextEditor::Document *tmpDoc=0;
+
+ KConfig *cfg=kapp->config();
+ QString previousGroup=cfg->group();
+ cfg->setGroup("KTEXTEDITOR:"+postfix);
+ QString editor=cfg->readPathEntry("editor");
+ cfg->setGroup(previousGroup);
+ if (editor.isEmpty())
+ {
+ KConfig *config=new KConfig("default_components");
+ config->setGroup("KTextEditor");
+ editor = config->readPathEntry("embeddedEditor", "katepart");
+ delete config;
+ }
+
+ KService::Ptr serv=KService::serviceByDesktopName(editor);
+ if (serv)
+ {
+ tmpDoc=KTextEditor::createDocument(serv->library().latin1(),parent,name);
+ if (tmpDoc) return tmpDoc;
+ }
+ if (fallBackToKatePart)
+ return KTextEditor::createDocument("libkatepart",parent,name);
+
+ return 0;
+}
+
+KTextEditor::Editor *EditorChooser::createEditor(QWidget *parentWidget,QObject *parent,const char* widgetName,
+ const char* name,const QString& postfix,bool fallBackToKatePart){
+
+ KTextEditor::Editor *tmpEd=0;
+
+ KConfig *cfg=kapp->config();
+ QString previousGroup=cfg->group();
+ cfg->setGroup("KTEXTEDITOR:"+postfix);
+ QString editor=cfg->readPathEntry("editor");
+ cfg->setGroup(previousGroup);
+ if (editor.isEmpty())
+ {
+ KConfig *config=new KConfig("default_components");
+ config->setGroup("KTextEditor");
+ editor = config->readPathEntry("embeddedEditor", "katepart");
+ delete config;
+ }
+
+ KService::Ptr serv=KService::serviceByDesktopName(editor);
+ if (serv)
+ {
+ tmpEd=KTextEditor::createEditor(serv->library().latin1(),parentWidget,widgetName,parent,name);
+ if (tmpEd) return tmpEd;
+ }
+ if (fallBackToKatePart)
+ return KTextEditor::createEditor("libkatepart",parentWidget,widgetName,parent,name);
+
+ return 0;
+}
+