File indexing completed on 2024-04-21 04:03:13

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_CLASS_WITH_JSON(cTestPlugin, "testplugin.json")
0096 
0097 cTestPlugin::cTestPlugin (QObject *, const QVariantList &)
0098 {
0099   // register the testing list
0100   cListManager::self()->registerType ("test", "Testing List", cTestList::newList);
0101 
0102   // your code here ...
0103   kDebug() << "Testing plugin loaded.";
0104 }
0105 
0106 cTestPlugin::~cTestPlugin()
0107 {
0108   // your code here ...
0109   kDebug() << "Testing plugin unloaded.";
0110 }
0111 
0112 
0113 void cTestPlugin::sessionAdd (int sess, bool fresh)
0114 {
0115   kDebug() << "Testing plugin: sessionAdd " << sess << ", " << (fresh?"fresh":"not fresh");
0116 }
0117 
0118 void cTestPlugin::sessionRemove (int sess, bool closed)
0119 {
0120   kDebug() << "Testing plugin: sessionRemoved " << sess << ", " << (closed?"closed":"not closed");
0121 }
0122 
0123 void cTestPlugin::sessionSwitch (int sess)
0124 {
0125   kDebug() << "Testing plugin: sessionSwitch " << sess;
0126 }
0127 
0128 void cTestPlugin::connected (int sess)
0129 {
0130   kDebug() << "Testing plugin: connected " << sess;
0131   
0132   cList *list = cListManager::self()->getList (sess, "test");
0133   if (!list) { kDebug() << "We do not have the list!" << endl; return; }
0134   list->addGroup (list->rootGroup(), "Testing Group 1");
0135   list->addGroup (list->rootGroup(), "Testing Group 2");
0136   list->addGroup (list->rootGroup(), "Testing Group 3");
0137   list->addGroup (list->group("Testing Group 2"), "Testing SubGroup 2A");
0138   cListObject *obj = list->newObject();
0139   list->addToGroup (list->group ("Testing Group 1"), obj);
0140   obj->setInt ("testint", 42);
0141   obj->setBool ("testbool", false);
0142   obj->setStr ("teststring", "Some&nbsp;<b>lions</b>.");
0143   list->setObjectName (obj, "xaxaxa");
0144   kDebug() << "List filled" << endl;
0145 /*
0146   QFile f ("testlist.xml");
0147   if (!f.open(QIODevice::ReadOnly | QIODevice::Text))
0148     return;
0149   QXmlStreamReader reader (&f);
0150   list->load (&reader);
0151   f.close();
0152   if (list->hasError()) kDebug() << list->lastError() << endl;
0153   else kDebug() << "List loaded" << endl;
0154 
0155   QFile file ("testlist2.xml");
0156   if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
0157     return;
0158   QXmlStreamWriter writer (&file);
0159   list->save (&writer);
0160   file.close();
0161   kDebug() << "List saved" << endl;
0162 */
0163 }
0164 
0165 void cTestPlugin::disconnected (int sess)
0166 {
0167   kDebug() << "Testing plugin: disconnected " << sess;
0168 
0169 }
0170 
0171 void cTestPlugin::rawData (int sess, char * data)
0172 {
0173   static bool first = false;
0174   if (!first)
0175     kDebug() << "Testing plugin: rawData " << sess << " (first call)";
0176   first = true;
0177 }
0178 
0179 void cTestPlugin::decompressedData (int sess, char * data)
0180 {
0181   static bool first = false;
0182   if (!first)
0183     kDebug() << "Testing plugin: decompressedData " << sess << " (first call)";
0184   first = true;
0185 }
0186 
0187 void cTestPlugin::processInput (int sess, int phase, cTextChunk * chunk,
0188     bool gagged)
0189 {
0190   static bool first = false;
0191   if (!first)
0192     kDebug() << "Testing plugin: processInput " << sess << " (first call)";
0193   first = true;
0194 }
0195 
0196 void cTestPlugin::processPrompt (int sess, cTextChunk * chunk)
0197 {
0198   static bool first = false;
0199   if (!first)
0200     kDebug() << "Testing plugin: processPrompt " << sess << " (first call)";
0201   first = true;
0202 }
0203 
0204 void cTestPlugin::processCommand (int sess, QString & command, bool & dontSend)
0205 {
0206   static bool first = false;
0207   if (!first)
0208     kDebug() << "Testing plugin: processCommand " << sess << " (first call)";
0209   first = true;
0210 }
0211 
0212 
0213 
0214 #include "testplugin.moc"