kateconfigplugindialogpage.cpp
00001 /* This file is part of the KDE project 00002 Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> 00003 Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License version 2 as published by the Free Software Foundation. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "kateconfigplugindialogpage.h" 00021 #include "kateconfigplugindialogpage.moc" 00022 00023 #include "katepluginmanager.h" 00024 #include "kateconfigdialog.h" 00025 #include <tdelistbox.h> 00026 #include "kateapp.h" 00027 #include <tqstringlist.h> 00028 #include <tqhbox.h> 00029 #include <tqlabel.h> 00030 #include <tdelocale.h> 00031 #include <tqpushbutton.h> 00032 #include <tqtooltip.h> 00033 #include <kiconloader.h> 00034 #include <tqwhatsthis.h> 00035 00036 class KatePluginListItem : public TQCheckListItem 00037 { 00038 public: 00039 KatePluginListItem(bool checked, KatePluginInfo *info, TQListView *parent); 00040 KatePluginInfo *info() const { return mInfo; } 00041 00042 protected: 00043 void stateChange(bool); 00044 00045 private: 00046 KatePluginInfo *mInfo; 00047 bool silentStateChange; 00048 }; 00049 00050 KatePluginListItem::KatePluginListItem(bool checked, KatePluginInfo *info, TQListView *parent) 00051 : TQCheckListItem(parent, info->service->name(), CheckBox) 00052 , mInfo(info) 00053 , silentStateChange(false) 00054 { 00055 silentStateChange = true; 00056 setOn(checked); 00057 silentStateChange = false; 00058 } 00059 00060 void KatePluginListItem::stateChange(bool b) 00061 { 00062 if(!silentStateChange) 00063 static_cast<KatePluginListView *>(listView())->stateChanged(this, b); 00064 } 00065 00066 KatePluginListView::KatePluginListView(TQWidget *parent, const char *name) 00067 : TDEListView(parent, name) 00068 { 00069 } 00070 00071 void KatePluginListView::stateChanged(KatePluginListItem *item, bool b) 00072 { 00073 emit stateChange(item, b); 00074 } 00075 00076 KateConfigPluginPage::KateConfigPluginPage(TQWidget *parent, KateConfigDialog *dialog):TQVBox(parent) 00077 { 00078 myDialog=dialog; 00079 00080 KatePluginListView* listView = new KatePluginListView(this); 00081 listView->addColumn(i18n("Name")); 00082 listView->addColumn(i18n("Comment")); 00083 TQWhatsThis::add(listView,i18n("Here you can see all available Kate plugins. Those with a check mark are loaded, and will be loaded again the next time Kate is started.")); 00084 00085 connect(listView, TQT_SIGNAL(stateChange(KatePluginListItem *, bool)), this, TQT_SLOT(stateChange(KatePluginListItem *, bool))); 00086 00087 KatePluginList &pluginList (KatePluginManager::self()->pluginList()); 00088 for (unsigned int i=0; i < pluginList.size(); ++i) 00089 { 00090 KatePluginListItem *item = new KatePluginListItem(pluginList[i].load, &pluginList[i], listView); 00091 item->setText(0, pluginList[i].service->name()); 00092 item->setText(1, pluginList[i].service->comment()); 00093 } 00094 } 00095 00096 void KateConfigPluginPage::stateChange(KatePluginListItem *item, bool b) 00097 { 00098 if(b) 00099 loadPlugin(item); 00100 else 00101 unloadPlugin(item); 00102 00103 emit changed(); 00104 } 00105 00106 void KateConfigPluginPage::loadPlugin (KatePluginListItem *item) 00107 { 00108 KatePluginManager::self()->loadPlugin (item->info()); 00109 KatePluginManager::self()->enablePluginGUI (item->info()); 00110 myDialog->addPluginPage (item->info()->plugin); 00111 00112 item->setOn(true); 00113 } 00114 00115 void KateConfigPluginPage::unloadPlugin (KatePluginListItem *item) 00116 { 00117 myDialog->removePluginPage (item->info()->plugin); 00118 KatePluginManager::self()->unloadPlugin (item->info()); 00119 00120 item->setOn(false); 00121 }