[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kwrite-devel
Subject:    [PATCH] K[write][ate] using KPluginSelector
From:       Rafael =?iso-8859-1?q?Fern=E1ndez_L=F3pez?= <ereslibre () gmail ! com>
Date:       2007-05-30 19:40:42
Message-ID: 200705302140.45390.ereslibre () gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


Hi all,

For improving an unified desktop and a consistent one, I have been doing some 
work on K[ate][write] for making it use KPluginSelector, instead of its own 
one.

I attach the patch I have written. I am having a strange issue: It will ignore 
any (de)selection you do, if it's not the last plugin shown. If the last 
plugin has been ticked, when you open again the dialog, all plugins are 
marked, and vice-versa.

I wrote this patch so quickly and without being familiar with this code, so it 
may contain "stupid" parts.

PS: Please CC me your replies, since I'm not suscribed to this list.


Bye and thanks,
Rafael Fernández López.

["katekpluginselector.diff" (text/x-diff)]

Index: plugins/wordcompletion/ktexteditor_docwordcompletion.desktop
===================================================================
--- plugins/wordcompletion/ktexteditor_docwordcompletion.desktop	(revisión: 669765)
+++ plugins/wordcompletion/ktexteditor_docwordcompletion.desktop	(copia de trabajo)
@@ -113,7 +113,7 @@
 Comment[x-test]=xxDirectional or popup-based completion from words in the documentxx
 Comment[zh_TW]=在編輯文件時的單字補完功能
 X-KDE-Library=ktexteditor_docwordcompletion
-ServiceTypes=KTextEditor/Plugin
+ServiceTypes=KTextEditor/Pluginzz
 Type=Service
 InitialPreference=8
 MimeType=text/plain
Index: dialogs/katedialogs.cpp
===================================================================
--- dialogs/katedialogs.cpp	(revisión: 669765)
+++ dialogs/katedialogs.cpp	(copia de trabajo)
@@ -78,6 +78,8 @@
 #include <kpushbutton.h>
 #include <kvbox.h>
 #include <kactioncollection.h>
+#include <kplugininfo.h>
+#include <kutils/kpluginselector.h>
 //#include <knewstuff/knewstuff.h>
 #include <QtGui/QCheckBox>
 #include <QtGui/QComboBox>
@@ -667,121 +669,46 @@
 
 //END KateSaveConfigTab
 
-//BEGIN PluginListItem
-class KatePartPluginListItem : public QTreeWidgetItem
-{
-  public:
-    KatePartPluginListItem(bool checked, uint i, const QString &name, QTreeWidget \
                *parent);
-    uint pluginIndex () const { return index; }
-
-  private:
-    uint index;
-};
-
-KatePartPluginListItem::KatePartPluginListItem(bool checked, uint i, const QString \
                &name, QTreeWidget *parent)
-  : QTreeWidgetItem(parent)
-  , index(i)
-{
-  setText(0, name);
-  setCheckState(0, checked ? Qt::Checked : Qt::Unchecked);
-}
-//END
-
-//BEGIN PluginListView
-KatePartPluginListView::KatePartPluginListView(QWidget *parent)
-  : QTreeWidget(parent)
-{
-}
-//END
-
 //BEGIN KatePartPluginConfigPage
 KatePartPluginConfigPage::KatePartPluginConfigPage (QWidget *parent) : \
KateConfigPage (parent, "")  {
-  // sizemanagment
-  QGridLayout *grid = new QGridLayout( this); //, 1, 1 );
-  grid->setSpacing( KDialog::spacingHint() );
+  QVBoxLayout *layout = new QVBoxLayout;
+  setLayout(layout);
 
-  listView = new KatePartPluginListView(this);
-  listView->setColumnCount(2);
-  listView->setHeaderLabels(QStringList() << i18n("Name") << i18n("Comment"));
-  listView->setRootIsDecorated(false);
-
-  grid->addWidget(listView, 0, 0);
-
-  for (int i=0; i<KateGlobal::self()->plugins().count(); i++)
+  KPluginInfo *it;
+  foreach (const KService::Ptr &service, KateGlobal::self()->plugins())
   {
-    KatePartPluginListItem *item = new \
KatePartPluginListItem(KateDocumentConfig::global()->plugin(i), i, \
                (KateGlobal::self()->plugins())[i]->name(), listView);
-    item->setText(0, (KateGlobal::self()->plugins())[i]->name());
-    item->setText(1, (KateGlobal::self()->plugins())[i]->comment());
-
-    m_items.append (item);
+    it = new KPluginInfo(service);
+    kDebug() << "new service registered for kate " << it->name() << endl;
+    plugins.append(it);
   }
-  listView->resizeColumnToContents(0);
 
-  // configure button
+  selector = new KPluginSelector(0);
 
-  btnConfigure = new QPushButton( i18n("Configure..."), this );
-  btnConfigure->setEnabled( false );
-  grid->addWidget( btnConfigure, 1, 0, Qt::AlignRight );
-  connect( btnConfigure, SIGNAL(clicked()), this, SLOT(slotConfigure()) );
+  connect(selector, SIGNAL(changed(bool)), this, SLOT(slotChanged()));
+  connect(selector, SIGNAL(configCommitted(QByteArray)), this, SLOT(slotChanged()));
 
-  connect( listView, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), \
                this, SLOT(slotCurrentChanged(QTreeWidgetItem*)) );
-  connect( listView, SIGNAL(itemChanged (QTreeWidgetItem *, int)), this, \
SLOT(slotChanged())); +  selector->addPlugins(plugins, "General Plugins");
+  layout->addWidget(selector);
 }
 
 KatePartPluginConfigPage::~KatePartPluginConfigPage ()
 {
-  qDeleteAll(m_items);
 }
 
 void KatePartPluginConfigPage::apply ()
 {
-  kDebug()<<"KatePartPluginConfigPage::apply (entered)"<<endl;
-  // nothing changed, no need to apply stuff
-  if (!hasChanged())
-    return;
-  m_changed = false;
-
-  kDebug()<<"KatePartPluginConfigPage::apply (need to store configuration)"<<endl;
-
-  KateDocumentConfig::global()->configStart ();
-
-  for (int i=0; i < m_items.count(); i++)
-    KateDocumentConfig::global()->setPlugin (m_items.at(i)->pluginIndex(), \
                m_items.at(i)->checkState(0) == Qt::Checked);
-
-  KateDocumentConfig::global()->configEnd ();
+  selector->save();
 }
 
-void KatePartPluginConfigPage::slotCurrentChanged( QTreeWidgetItem* i )
+void KatePartPluginConfigPage::reload ()
 {
-  KatePartPluginListItem *item = static_cast<KatePartPluginListItem *>(i);
-  if ( ! item ) return;
-
-    bool b = false;
-  if ( item->checkState(0) == Qt::Checked )
-  {
-    // load this plugin, and see if it has config pages
-    KTextEditor::Plugin *plugin = \
KTextEditor::createPlugin(QFile::encodeName((KateGlobal::self()->plugins())[item->pluginIndex()]->library()), \
                0);
-    if ( plugin ) {
-      b = plugin->configDialogSupported();
-      delete plugin;
-    }
-  }
-
-  btnConfigure->setEnabled( b );
+  selector->load();
 }
 
-void KatePartPluginConfigPage::slotConfigure()
+void KatePartPluginConfigPage::defaults ()
 {
-  KatePartPluginListItem *item = \
                static_cast<KatePartPluginListItem*>(listView->currentItem());
-  KTextEditor::Plugin *plugin =
-    KTextEditor::createPlugin(QFile::encodeName((KateGlobal::self()->plugins())[item->pluginIndex()]->library()), \
                0);
-
-  if ( ! plugin ) return;
-
-  plugin->configDialog (this);
-
-  delete plugin;
+  selector->defaults();
 }
 //END KatePartPluginConfigPage
 
Index: dialogs/katedialogs.h
===================================================================
--- dialogs/katedialogs.h	(revisión: 669765)
+++ dialogs/katedialogs.h	(copia de trabajo)
@@ -41,8 +41,6 @@
 #include <QtGui/QTabWidget>
 #include <QtGui/QTreeWidget>
 
-class KatePartPluginListItem;
-
 struct syntaxContextData;
 
 class KateDocument;
@@ -62,6 +60,8 @@
 class KPushButton;
 class KRegExpDialog;
 class KIntNumInput;
+class KPluginSelector;
+class KPluginInfo;
 
 class QGroupBox;
 class QCheckBox;
@@ -250,24 +250,6 @@
   Ui::OpenSaveConfigWidget* ui;
 };
 
-class KatePartPluginListItem;
-
-class KatePartPluginListView : public QTreeWidget
-{
-  Q_OBJECT
-
-  friend class KatePartPluginListItem;
-
-  public:
-    KatePartPluginListView (QWidget *parent = 0);
-
-  Q_SIGNALS:
-    void stateChange(KatePartPluginListItem *, bool);
-
-  private:
-    void stateChanged(KatePartPluginListItem *, bool);
-};
-
 class KatePartPluginConfigPage : public KateConfigPage
 {
   Q_OBJECT
@@ -278,18 +260,13 @@
 
   public Q_SLOTS:
     void apply ();
-    void reload () {}
+    void reload ();
     void reset () {}
-    void defaults () {}
+    void defaults ();
 
-  private Q_SLOTS:
-    void slotCurrentChanged( QTreeWidgetItem* );
-    void slotConfigure();
-
   private:
-    KatePartPluginListView *listView;
-    QList<KatePartPluginListItem*> m_items;
-    class QPushButton *btnConfigure;
+    KPluginSelector *selector;
+    QList<KPluginInfo*> plugins;
 };
 
 class KateScriptNewStuff;
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revisión: 669765)
+++ CMakeLists.txt	(copia de trabajo)
@@ -29,6 +29,7 @@
   ${CMAKE_SOURCE_DIR}/kde3support
   ${CMAKE_SOURCE_DIR}/kde3support/kdeui
   ${CMAKE_SOURCE_DIR}/kjsembed
+  ${CMAKE_SOURCE_DIR}/kutils
   ${KDE4_KIO_INCLUDES})
 
 # kjs hash stuff
@@ -136,7 +137,7 @@
 kde4_add_plugin(katepart ${katepart_PART_SRCS})
 
 # linking
-target_link_libraries(katepart ${KDE4_KDECORE_LIBS} ktexteditor kdeprint kjs \
kde3support ) +target_link_libraries(katepart ${KDE4_KDECORE_LIBS} kutils ktexteditor \
kdeprint kjs kde3support )  
 if(KDE4_ENABLE_FINAL)
 	macro_add_file_dependencies(${CMAKE_CURRENT_BINARY_DIR}/katepart_final_cpp.cpp \
${CMAKE_CURRENT_BINARY_DIR}/katejscript.lut.h )


[Attachment #8 (application/pgp-signature)]

_______________________________________________
KWrite-Devel mailing list
KWrite-Devel@kde.org
https://mail.kde.org/mailman/listinfo/kwrite-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic