diff options
author | Timothy Pearson <[email protected]> | 2013-01-26 13:17:21 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2013-01-26 13:17:21 -0600 |
commit | dfe289850f068f19ba4a83ab4e7e22a7e09c13c9 (patch) | |
tree | c297348a55df66c571de4525646e0b9762427353 /interfaces/tdetexteditor/editorchooser.cpp | |
parent | b7658a0d5eca24a9d37c6e04f88298ef02389db0 (diff) | |
download | tdelibs-dfe289850f068f19ba4a83ab4e7e22a7e09c13c9.tar.gz tdelibs-dfe289850f068f19ba4a83ab4e7e22a7e09c13c9.zip |
Rename a number of libraries and executables to avoid conflicts with KDE4
Diffstat (limited to 'interfaces/tdetexteditor/editorchooser.cpp')
-rw-r--r-- | interfaces/tdetexteditor/editorchooser.cpp | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/interfaces/tdetexteditor/editorchooser.cpp b/interfaces/tdetexteditor/editorchooser.cpp new file mode 100644 index 000000000..807d342d0 --- /dev/null +++ b/interfaces/tdetexteditor/editorchooser.cpp @@ -0,0 +1,162 @@ +#include <editorchooser.h> +#include <editorchooser.moc> + +#include <tqcombobox.h> +#include <ktrader.h> +#include <kconfig.h> +#include <tqstringlist.h> +#include <kservice.h> +#include <klocale.h> +#include <tqlabel.h> +#include <kapplication.h> +#include <tqlayout.h> + +#include "editorchooser_ui.h" + +using namespace KTextEditor; + +namespace KTextEditor +{ + class PrivateEditorChooser + { + public: + PrivateEditorChooser() + { + } + ~PrivateEditorChooser(){} + // Data Members + EditorChooser_UI *chooser; + TQStringList ElementNames; + TQStringList elements; + }; + +} + +EditorChooser::EditorChooser(TQWidget *parent,const char *name) : + TQWidget (parent,name) + { + d = new PrivateEditorChooser (); + + // sizemanagment + TQGridLayout *grid = new TQGridLayout( 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"); + TDEConfig *config=new TDEConfig("default_components"); + config->setGroup("KTextEditor"); + TQString 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(TQString(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 TQString& postfix){ + TDEConfig *cfg=kapp->config(); + TQString previousGroup=cfg->group(); + cfg->setGroup("KTEXTEDITOR:"+postfix); + TQString 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 TQString& postfix){ + TDEConfig *cfg=kapp->config(); + TQString 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) ? + TQString::null : (*d->elements.at(d->chooser->editorCombo->currentItem()-1))); + cfg->sync(); + cfg->setGroup(previousGroup); + +} + +KTextEditor::Document *EditorChooser::createDocument(TQObject *parent,const char* name, const TQString& postfix,bool fallBackToKatePart){ + + KTextEditor::Document *tmpDoc=0; + + TDEConfig *cfg=kapp->config(); + TQString previousGroup=cfg->group(); + cfg->setGroup("KTEXTEDITOR:"+postfix); + TQString editor=cfg->readPathEntry("editor"); + cfg->setGroup(previousGroup); + if (editor.isEmpty()) + { + TDEConfig *config=new TDEConfig("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(TQWidget *parentWidget,TQObject *parent,const char* widgetName, + const char* name,const TQString& postfix,bool fallBackToKatePart){ + + KTextEditor::Editor *tmpEd=0; + + TDEConfig *cfg=kapp->config(); + TQString previousGroup=cfg->group(); + cfg->setGroup("KTEXTEDITOR:"+postfix); + TQString editor=cfg->readPathEntry("editor"); + cfg->setGroup(previousGroup); + if (editor.isEmpty()) + { + TDEConfig *config=new TDEConfig("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; +} + |