File indexing completed on 2023-09-24 04:17:34

0001 //
0002 // C++ Implementation: testplugin
0003 //
0004 // Description: Testing plugin.
0005 //
0006 /*
0007 Copyright 2007-2011 Tomas Mecir <kmuddy@kmuddy.com>
0008 
0009 This program is free software; you can redistribute it and/or
0010 modify it under the terms of the GNU General Public License as
0011 published by the Free Software Foundation; either version 2 of 
0012 the License, or (at your option) any later version.
0013 
0014 This program is distributed in the hope that it will be useful,
0015 but WITHOUT ANY WARRANTY; without even the implied warranty of
0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017 GNU General Public License for more details.
0018 
0019 You should have received a copy of the GNU General Public License
0020 along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 
0023 #include "testplugin.h"
0024 
0025 #include "clistobject.h"
0026 #include "clist.h"
0027 #include "clistmanager.h"
0028 #include "clistgroupeditor.h"
0029 
0030 #include <kdebug.h>
0031 
0032 #include <kpluginfactory.h>
0033 #include <kpluginloader.h>
0034 #include <klineedit.h>
0035 
0036 #include <QVBoxLayout>
0037 #include <QFile>
0038 #include <QXmlStreamReader>
0039 #include <QXmlStreamWriter>
0040 
0041 class cTestEditor : public cListEditor {
0042  public:
0043   cTestEditor (QWidget *parent) : cListEditor (parent) {
0044   }
0045 
0046   void createGUI (QWidget *parent)
0047   {
0048     QVBoxLayout *layout = new QVBoxLayout (parent);
0049     line = new KLineEdit (parent);
0050     QWidget *commonEditor = createCommonAttribEditor (parent);
0051     layout->addWidget (line);
0052     layout->addWidget (commonEditor);
0053   }
0054 
0055   void fillGUI (const cListObjectData &data)
0056   {
0057     fillCommonAttribEditor (data);
0058     line->setText (data.strValue("text"));
0059   }
0060 
0061   void getDataFromGUI (cListObjectData *data)
0062   {
0063     getDataFromCommonAttribEditor (data);
0064     data->strValues["text"] = line->text();
0065   }
0066 
0067  private:
0068   KLineEdit *line;
0069 };
0070 
0071 class cTestObject : public cListObject {
0072  public:
0073  protected:
0074   cTestObject (cList *list, QStandardItem *modelItem = 0)
0075     : cListObject (list, modelItem) {
0076   }
0077   virtual ~cTestObject () {}
0078 
0079   friend class cTestList;
0080 };
0081 
0082 class cTestList : public cList {
0083  public:
0084   cTestList () : cList ("test") {
0085     addBoolProperty ("testbool", "Testing boolean property", true);
0086   }
0087   virtual ~cTestList () {};
0088   static cList *newList () { return new cTestList; };
0089   virtual cListObject *newObject () { return new cTestObject (this); };
0090   virtual QString objName () { return "Testing Object"; }
0091   virtual cListEditor *editor (QWidget *parent) { return new cTestEditor (parent); };
0092 
0093 };
0094 
0095 K_PLUGIN_FACTORY (cTestPluginFactory, registerPlugin<cTestPlugin>();)
0096 K_EXPORT_PLUGIN (cTestPluginFactory("kmuddy"))
0097 
0098 cTestPlugin::cTestPlugin (QObject *, const QVariantList &)
0099 {
0100   // register the testing list
0101   cListManager::self()->registerType ("test", "Testing List", cTestList::newList);
0102 
0103   // your code here ...
0104   kDebug() << "Testing plugin loaded.";
0105 }
0106 
0107 cTestPlugin::~cTestPlugin()
0108 {
0109   // your code here ...
0110   kDebug() << "Testing plugin unloaded.";
0111 }
0112 
0113 
0114 void cTestPlugin::sessionAdd (int sess, bool fresh)
0115 {
0116   kDebug() << "Testing plugin: sessionAdd " << sess << ", " << (fresh?"fresh":"not fresh");
0117 }
0118 
0119 void cTestPlugin::sessionRemove (int sess, bool closed)
0120 {
0121   kDebug() << "Testing plugin: sessionRemoved " << sess << ", " << (closed?"closed":"not closed");
0122 }
0123 
0124 void cTestPlugin::sessionSwitch (int sess)
0125 {
0126   kDebug() << "Testing plugin: sessionSwitch " << sess;
0127 }
0128 
0129 void cTestPlugin::connected (int sess)
0130 {
0131   kDebug() << "Testing plugin: connected " << sess;
0132   
0133   cList *list = cListManager::self()->getList (sess, "test");
0134   if (!list) { kDebug() << "We do not have the list!" << endl; return; }
0135   list->addGroup (list->rootGroup(), "Testing Group 1");
0136   list->addGroup (list->rootGroup(), "Testing Group 2");
0137   list->addGroup (list->rootGroup(), "Testing Group 3");
0138   list->addGroup (list->group("Testing Group 2"), "Testing SubGroup 2A");
0139   cListObject *obj = list->newObject();
0140   list->addToGroup (list->group ("Testing Group 1"), obj);
0141   obj->setInt ("testint", 42);
0142   obj->setBool ("testbool", false);
0143   obj->setStr ("teststring", "Some&nbsp;<b>lions</b>.");
0144   list->setObjectName (obj, "xaxaxa");
0145   kDebug() << "List filled" << endl;
0146 /*
0147   QFile f ("testlist.xml");
0148   if (!f.open(QIODevice::ReadOnly | QIODevice::Text))
0149     return;
0150   QXmlStreamReader reader (&f);
0151   list->load (&reader);
0152   f.close();
0153   if (list->hasError()) kDebug() << list->lastError() << endl;
0154   else kDebug() << "List loaded" << endl;
0155 
0156   QFile file ("testlist2.xml");
0157   if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
0158     return;
0159   QXmlStreamWriter writer (&file);
0160   list->save (&writer);
0161   file.close();
0162   kDebug() << "List saved" << endl;
0163 */
0164 }
0165 
0166 void cTestPlugin::disconnected (int sess)
0167 {
0168   kDebug() << "Testing plugin: disconnected " << sess;
0169 
0170 }
0171 
0172 void cTestPlugin::rawData (int sess, char * data)
0173 {
0174   static bool first = false;
0175   if (!first)
0176     kDebug() << "Testing plugin: rawData " << sess << " (first call)";
0177   first = true;
0178 }
0179 
0180 void cTestPlugin::decompressedData (int sess, char * data)
0181 {
0182   static bool first = false;
0183   if (!first)
0184     kDebug() << "Testing plugin: decompressedData " << sess << " (first call)";
0185   first = true;
0186 }
0187 
0188 void cTestPlugin::processInput (int sess, int phase, cTextChunk * chunk,
0189     bool gagged)
0190 {
0191   static bool first = false;
0192   if (!first)
0193     kDebug() << "Testing plugin: processInput " << sess << " (first call)";
0194   first = true;
0195 }
0196 
0197 void cTestPlugin::processPrompt (int sess, cTextChunk * chunk)
0198 {
0199   static bool first = false;
0200   if (!first)
0201     kDebug() << "Testing plugin: processPrompt " << sess << " (first call)";
0202   first = true;
0203 }
0204 
0205 void cTestPlugin::processCommand (int sess, QString & command, bool & dontSend)
0206 {
0207   static bool first = false;
0208   if (!first)
0209     kDebug() << "Testing plugin: processCommand " << sess << " (first call)";
0210   first = true;
0211 }
0212 
0213 
0214 
0215 #include "testplugin.moc"