diff options
| author | 2009-02-06 17:08:33 +0000 | |
|---|---|---|
| committer | 2009-02-06 17:08:33 +0000 | |
| commit | 0d67412f4d89d7d46229916955550917787c3104 (patch) | |
| tree | 3f69288a45860acb33bfda01a305c5d8c47850c5 /src/modules/objects | |
| parent | small fix for torrent module (diff) | |
| download | KVIrc-0d67412f4d89d7d46229916955550917787c3104.tar.gz KVIrc-0d67412f4d89d7d46229916955550917787c3104.tar.bz2 KVIrc-0d67412f4d89d7d46229916955550917787c3104.zip | |
New kvs classes(w.i.p.)
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@3069 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules/objects')
| -rw-r--r-- | src/modules/objects/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | src/modules/objects/class_datetimeedit.cpp | 148 | ||||
| -rw-r--r-- | src/modules/objects/class_datetimeedit.h | 53 | ||||
| -rw-r--r-- | src/modules/objects/class_sql.cpp | 420 | ||||
| -rw-r--r-- | src/modules/objects/class_sql.h | 67 | ||||
| -rw-r--r-- | src/modules/objects/class_tablewidget.cpp | 222 | ||||
| -rw-r--r-- | src/modules/objects/class_tablewidget.h | 62 | ||||
| -rw-r--r-- | src/modules/objects/libkviobjects.cpp | 23 |
8 files changed, 994 insertions, 7 deletions
diff --git a/src/modules/objects/CMakeLists.txt b/src/modules/objects/CMakeLists.txt index 29ce6626e..9c251d71f 100644 --- a/src/modules/objects/CMakeLists.txt +++ b/src/modules/objects/CMakeLists.txt @@ -11,6 +11,7 @@ SET(kviobjects_MOC_HDRS class_button.h class_checkbox.h class_combobox.h + class_datetimeedit.h class_dockwindow.h class_ftp.h class_http.h @@ -26,12 +27,14 @@ SET(kviobjects_MOC_HDRS class_socket.h class_spinbox.h class_tabwidget.h + class_tablewidget.h class_tbrowser.h class_toolbutton.h class_treewidget.h class_widget.h class_window.h class_wizard.h + class_sql.h ) SET(kviobjects_SRCS @@ -40,6 +43,7 @@ SET(kviobjects_SRCS class_buttongroup.cpp class_checkbox.cpp class_combobox.cpp + class_datetimeedit.cpp class_dialog.cpp class_dockwindow.cpp class_file.cpp @@ -67,6 +71,7 @@ SET(kviobjects_SRCS class_socket.cpp class_spinbox.cpp class_tabwidget.cpp + class_tablewidget.cpp class_tbrowser.cpp class_toolbar.cpp class_toolbutton.cpp @@ -79,6 +84,7 @@ SET(kviobjects_SRCS class_workspace.cpp class_wrapper.cpp class_xmlreader.cpp + class_sql.cpp ) # After this call, files will be moc'ed to moc_kvi_*.cpp diff --git a/src/modules/objects/class_datetimeedit.cpp b/src/modules/objects/class_datetimeedit.cpp new file mode 100644 index 000000000..b2a7d8ad0 --- /dev/null +++ b/src/modules/objects/class_datetimeedit.cpp @@ -0,0 +1,148 @@ +//============================================================================= +// +// File : class_datetimeedit.cpp +// Creation date : Wed 30 Gen 2009 09:30:05 CEST by Carbone Alessandro +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2000-2008 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= + +#include "kvi_debug.h" +#include "kvi_locale.h" +#include "kvi_error.h" +#include "kvi_iconmanager.h" +#include "kvi_file.h" + +#include "class_datetimeedit.h" +#include "class_pixmap.h" + + #include <QDateTimeEdit> + +/* + @doc:button + @title: + button class + @type: + class + @short: + Button widget. + @inherits: + [class]object[/class] + [class]button[/class] + @description: + This widget provides a push button + @functions: + !fn: $setText([<text:string>]) + @signals: + !sg: $clicked() + This signal is emitted by the default implementation of [classfnc]$clickEvent[/classfnc](). + +*/ + + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_datetimeedit,"datetimeedit","widget") + + /*KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_datetimeedit,setText) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_datetimeedit,text) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_datetimeedit,clickEvent) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_datetimeedit,setImage) +*/ +KVSO_END_REGISTERCLASS(KviKvsObject_datetimeedit) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_datetimeedit,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_datetimeedit) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_datetimeedit) + +KVSO_END_DESTRUCTOR(KviKvsObject_datetimeedit) + +bool KviKvsObject_datetimeedit::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + SET_OBJECT(QDateTimeEdit); +// connect(widget(),SIGNAL(clicked()),this,SLOT(slotClicked())); + return true; +} +/* +KVSO_CLASS_FUNCTION(button,text) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setString(((QPushButton *)widget())->text()); + return true; +} + +KVSO_CLASS_FUNCTION(button,setText) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + ((QPushButton *)widget())->setText(szText); + return true; +} + +KVSO_CLASS_FUNCTION(datetimeedit,setImage) +{ + CHECK_INTERNAL_POINTER(widget()) + KviKvsVariant icon; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("icon_or_hobject",KVS_PT_VARIANT,0,icon) + KVSO_PARAMETERS_END(c) + if(icon.isHObject()) + { + kvs_hobject_t hObj; + icon.asHObject(hObj); + KviKvsObject *pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObj); + if (!pObject) + { + c->warning(__tr2qs_ctx("Pixmap parameter is not an object!","objects")); + return true; + } + if(pObject->inheritsClass("pixmap")) + ((QPushButton *)widget())->setIcon(QIcon(*((KviKvsObject_pixmap *)pObject)->getPixmap())); + else{ + c->warning(__tr2qs_ctx("Object Pixmap required!","object")); + } + return true; + } + QString szIcon; + icon.asString(szIcon); + QPixmap * pix = g_pIconManager->getImage(szIcon); + if(pix) ((QPushButton *)widget())->setIcon(*pix); + else((QPushButton *)widget())->setIcon(QIcon()); + return true; +} +KVSO_CLASS_FUNCTION(button,clickEvent) +{ + emitSignal("clicked",c); + return true; +} + +// slots +void KviKvsObject_datetimeedit::slotClicked() +{ + KviKvsVariantList *params=0; + callFunction(this,"clickEvent",params); +} +*/ + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_class_datetimeedit.moc" +#endif //COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/objects/class_datetimeedit.h b/src/modules/objects/class_datetimeedit.h new file mode 100644 index 000000000..842934c53 --- /dev/null +++ b/src/modules/objects/class_datetimeedit.h @@ -0,0 +1,53 @@ +#ifndef _CLASS_datetimeedit_H_ +#define _CLASS_datetimeedit_H_ +//============================================================================= +// +// File : class_datetimeedit.h +// Creation date : Wed 30 Gen 2009 09:30:05 CEST by Carbone Alessandro +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2000 Krzysztof Godlewski +// Copyright (C) 2000-2008 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= + + + +#include "class_widget.h" +#include "object_macros.h" + +class KviKvsObject_datetimeedit : public KviKvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_datetimeedit) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + +/*bool setText(KviKvsObjectFunctionCall *c); + bool text(KviKvsObjectFunctionCall *c); + + bool setImage(KviKvsObjectFunctionCall *c); + bool clickEvent(KviKvsObjectFunctionCall *c); +*/ +protected slots: + //void slotClicked(); +}; + +#endif // !_CLASS_datetimeedit_H_ diff --git a/src/modules/objects/class_sql.cpp b/src/modules/objects/class_sql.cpp new file mode 100644 index 000000000..0101ba052 --- /dev/null +++ b/src/modules/objects/class_sql.cpp @@ -0,0 +1,420 @@ +//============================================================================= +// +// File : class_sql.cpp +// Creation date : Wed Gen 28 2009 21:07:55 by Alessandro Carbone +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2000-2008 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================ + +#include "kvi_debug.h" +#include "kvi_malloc.h" +#include "kvi_locale.h" +#include "class_sql.h" +#include <QtSql> +#include "class_memorybuffer.h" +#include <stdlib.h> +#include <QHash> + +#define CHECK_QUERY_IS_INIT if (!currentSQlQuery)\ + {\ + c->error("No query has been initialized!");\ + return false;} + + +/* + @doc: sql + @keyterms: + Sql database. + @title: + sql class + @type: + class + @short: + A sql database interface. + @inherits: + [class]object[/class] + @description: + This class permits KVIrc to have an interface with a SQL database supported by Qt library drivers. + @functions: + !fn: <boolean> $setConnection(<connection_name:string>,<database_name:string>,[<user:string>,<host_name_string>,<password:string>,<database_driver:string>]) + Connects to the DBMS using the connection <connection_name> and selecting the database <database_name>.[br] + If the optional parameter <database_driver> is passed, it will be used the corresponding driver (if present), otherwise Sqlite will be used. + Returns true if the operation is successful, false otherwise. + !fn: $queryInit(<connection_name:string>) + Initialize the query for the database <connection_name> which has to be already connected. + !fn: $setCurrentQuery(<connection_name:string>) + Sets the query for the database connection <connection_name> , which has to be already connected, as current query. + !fn: <connection_name:string> $currentQuery() + Returns the name of the database connection for the current query, or an empty string if there aren't any initialized queries. + !fn: $closeConnection(<connection_name:string>) + Closes the connection <connection_name>. + !fn: <size:integer> $queryResultsSize() + Returns the query size in rows or -1 if the query is empty or the database driver doesn' support the function. + !fn: <ok:boolean> $queryExec([<query:string>]) + Execs the current query <query>. The string must follow the right syntax against the database in use. + If there are no parameters, it will exec the query previously done. + After the execution, the query will positioned on the first resulting record. + Returns true if the operation is successful, false otherwise. + See also [classfnc]$queryPrepare[/classfnc]() + !fn: <ok:boolean> $queryPrepare(<query_string>) + Prepare the query <query> to execute. The string must follow the right syntax against the database in use. + It's possible to use the placeholders. It's supported either the identifier ':' and '?' but it's not possible to use them together. + Returns true if the operation is successful, false otherwise. + See also [classfnc]$queryExec[/classfnc]and[classfnc]$queryBindValue[/classfnc. + !fn: $queryBindValue() + Sets the placeholder <placeholder> to be bound to the value <val> in the prepared statement. + Note that the placeholder mark (e.g :) must be included when specifing the placeholder name. + !fn: <boolean> $queryPrevious() + Sets the current query position to the previous resulting record. + Returns true if the operation is successful, false otherwise. + !fn: <boolean> $queryNext() + Sets the current query position to the next resulting record. + Returns true if the operation is successful, false otherwise. + !fn: <boolean> $queryLast() + Sets the current query position to the last resulting record. + Returns true if the operation is successful, false otherwise. + !fn: <boolean> $queryFirst() + Sets the current query position to the first resulting record. + Returns true if the operation is successful, false otherwise. + !fn: <record:hash> $queryRecord() + Returns a hash containing the current query's record fields. + !fn: $queryFinish() + Sets the current query to inactive. +*/ + + + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_sql,"sql","object") + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_sql,setConnection) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_sql,setCurrentQuery) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_sql,currentQuery) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_sql,closeConnection) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_sql,queryInit) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_sql,queryFinish) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_sql,queryResultsSize) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_sql,queryExec) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_sql,queryPrepare) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_sql,queryBindValue) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_sql,queryPrevious) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_sql,queryNext) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_sql,queryLast) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_sql,queryFirst) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_sql,queryRecord) + +KVSO_END_REGISTERCLASS(KviKvsObject_sql) + + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_sql,KviKvsObject) +currentSQlQuery=0; +KVSO_END_CONSTRUCTOR(KviKvsObject_sql) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_sql) +QHashIterator<QString,QSqlQuery *> t(connectionsDict); +while (t.hasNext()) +{ + t.next(); + QString szConnectionName=t.key(); + connectionsDict.value(szConnectionName)->finish(); + delete connectionsDict.value(szConnectionName); + QSqlDatabase::removeDatabase(szConnectionName); +} +connectionsDict.clear(); + +KVSO_END_DESTRUCTOR(KviKvsObject_sql) + +KVSO_CLASS_FUNCTION(sql,setConnection) +{ + QString szConnectionName,szDbName,szDbDriver,szUserName,szHostName,szPassword; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("connection_name",KVS_PT_STRING,0,szConnectionName) + KVSO_PARAMETER("database_name",KVS_PT_STRING,0,szDbName) + KVSO_PARAMETER("user_name",KVS_PT_STRING,KVS_PF_OPTIONAL,szUserName) + KVSO_PARAMETER("host_name",KVS_PT_STRING,KVS_PF_OPTIONAL,szHostName) + KVSO_PARAMETER("password",KVS_PT_STRING,KVS_PF_OPTIONAL,szPassword) + KVSO_PARAMETER("dabaseType",KVS_PT_STRING,KVS_PF_OPTIONAL,szDbDriver) + KVSO_PARAMETERS_END(c) + if(!szDbDriver.isEmpty()) + { + QStringList drivers = QSqlDatabase::drivers(); + if (!drivers.contains(szDbDriver)) + { + c->error(__tr2qs_ctx("Missing QT plugin for database %Q","objects"),&szDbDriver); + return false; + } + } + else szDbDriver="QSQLITE"; + QSqlDatabase db=QSqlDatabase::addDatabase(szDbDriver,szConnectionName); + db.setDatabaseName(szDbName); + db.setHostName(szHostName); + db.setUserName(szUserName); + db.setPassword(szPassword); + + c->returnValue()->setBoolean(db.open()); + return true; +} +KVSO_CLASS_FUNCTION(sql,closeConnection) +{ + QString szConnectionName; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("connectionName",KVS_PT_STRING,0,szConnectionName) + KVSO_PARAMETERS_END(c) + + QStringList connections = QSqlDatabase::connectionNames(); + if (!connections.contains(szConnectionName)) + { + c->warning(__tr2qs_ctx("Connection %Q does not exists","objects"),&szConnectionName); + return true; + } + if (connectionsDict.value(szConnectionName)) + { + if (connectionsDict.value(szConnectionName)==currentSQlQuery) currentSQlQuery=0; + connectionsDict.value(szConnectionName)->finish(); + delete connectionsDict.value(szConnectionName); + connectionsDict.remove(szConnectionName); + } + QSqlDatabase::removeDatabase(szConnectionName); + + return true; +} +KVSO_CLASS_FUNCTION(sql,setCurrentQuery) +{ + QString szConnectionName; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("connection_name",KVS_PT_STRING,0,szConnectionName) + KVSO_PARAMETERS_END(c) + QSqlQuery *q=connectionsDict.value(szConnectionName); + if(!q) + { + c->warning(__tr2qs_ctx("Connection query %Q does not exists","objects"),&szConnectionName); + return true; + } + currentSQlQuery=q; + return true; +} +KVSO_CLASS_FUNCTION(sql,queryFinish) +{ + QString szConnectionName; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("connection_name",KVS_PT_STRING,KVS_PF_OPTIONAL,szConnectionName) + KVSO_PARAMETERS_END(c) + QSqlQuery *q; + if(szConnectionName.isEmpty()) + { + q=currentSQlQuery; + if (!q) + { + c->warning(__tr2qs_ctx("No query connection is open","objects")); + return true; + } + } + else + { + q=connectionsDict.value(szConnectionName); + if(!q) + { + c->warning(__tr2qs_ctx("Query for connection %Q does not exists","objects"),&szConnectionName); + return true; + } + } + q->finish(); + return true; +} +KVSO_CLASS_FUNCTION(sql,currentQuery) +{ + if (!currentSQlQuery) c->returnValue()->setString(QString()); + else + { + QString szKey=connectionsDict.key(currentSQlQuery); + c->returnValue()->setString(szKey); + } + return true; +} +KVSO_CLASS_FUNCTION(sql,queryInit) +{ + QString szConnectionName; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("connection_name",KVS_PT_STRING,0,szConnectionName) + KVSO_PARAMETERS_END(c) + if (connectionsDict.value(szConnectionName)) + { + c->warning(__tr2qs_ctx("Query %Q already initializated","objects"),&szConnectionName); + return true; + } + if(!QSqlDatabase::connectionNames().contains(szConnectionName)) + { + c->error(__tr2qs_ctx("Connection %Q is not open!","objects"),&szConnectionName); + return false; + } + currentSQlQuery=new QSqlQuery(QSqlDatabase::database(szConnectionName)); + connectionsDict[szConnectionName]=currentSQlQuery; + return true; +} + + +KVSO_CLASS_FUNCTION(sql,queryPrepare) +{ + CHECK_QUERY_IS_INIT + QString szQuery; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("query",KVS_PT_STRING,0,szQuery) + KVSO_PARAMETERS_END(c) + c->returnValue()->setBoolean(currentSQlQuery->prepare(szQuery)); + return true; +} +KVSO_CLASS_FUNCTION(sql,queryBindValue) +{ + CHECK_QUERY_IS_INIT + QString szFieldName; + KviKvsVariant *v; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bindName",KVS_PT_STRING,0,szFieldName) + KVSO_PARAMETER("value",KVS_PT_VARIANT,0,v) + KVSO_PARAMETERS_END(c) + QString szType; + v->getTypeName(szType); + if (v->isString()) + { + QString szText; + v->asString(szText); + currentSQlQuery->bindValue(szFieldName,QVariant(szText)); + } + else if (v->isReal()) + { + kvs_real_t i; + v->asReal(i); + currentSQlQuery->bindValue(szFieldName,QVariant((double)i)); + } + else if (v->isInteger()) + { + kvs_int_t i; + v->asInteger(i); + currentSQlQuery->bindValue(szFieldName,QVariant((int)i)); + } + else if (v->isBoolean()) + { + bool b=v->asBoolean(); + currentSQlQuery->bindValue(szFieldName,QVariant(b)); + } + else if (v->isHObject()) + { + kvs_hobject_t hOb; + v->asHObject(hOb); + KviKvsObject *pObject; + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hOb); + if (pObject->inheritsClass("memorybuffer")) + currentSQlQuery->bindValue(szFieldName,QVariant(*((KviKvsObject_memorybuffer *)pObject)->pBuffer())); + else c->warning(__tr2qs_ctx("Only memorybuffer class object is supported","objects")); + } + else + { + QString szTypeName; + v->getTypeName(szTypeName); + c->warning(__tr2qs_ctx("Type value %Q not supported","objects"),&szTypeName); + } + return true; +} + +KVSO_CLASS_FUNCTION(sql,queryExec) +{ + CHECK_QUERY_IS_INIT + QString szQuery; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("query",KVS_PT_STRING,KVS_PF_OPTIONAL,szQuery) + KVSO_PARAMETERS_END(c) + bool bOk; + if (szQuery.isEmpty()) bOk=currentSQlQuery->exec(); + else bOk=currentSQlQuery->exec(szQuery); + c->returnValue()->setBoolean(bOk); + return true; +} +KVSO_CLASS_FUNCTION(sql,queryNext) +{ + CHECK_QUERY_IS_INIT + if (currentSQlQuery->isActive() && currentSQlQuery->isSelect()) c->returnValue()->setBoolean(currentSQlQuery->next()); + else c->returnValue()->setNothing(); + return true; +} +KVSO_CLASS_FUNCTION(sql,queryPrevious) +{ + CHECK_QUERY_IS_INIT + if (currentSQlQuery->isActive() && currentSQlQuery->isSelect()) c->returnValue()->setBoolean(currentSQlQuery->previous()); + else c->returnValue()->setNothing(); + return true; +} +KVSO_CLASS_FUNCTION(sql,queryResultsSize) +{ + CHECK_QUERY_IS_INIT + c->returnValue()->setInteger(currentSQlQuery->size()); + return true; +} +KVSO_CLASS_FUNCTION(sql,queryFirst) +{ + CHECK_QUERY_IS_INIT + if (currentSQlQuery->isActive() && currentSQlQuery->isSelect()) c->returnValue()->setBoolean(currentSQlQuery->first()); + return true; +} +KVSO_CLASS_FUNCTION(sql,queryLast) +{ + CHECK_QUERY_IS_INIT + if (currentSQlQuery->isActive() && currentSQlQuery->isSelect()) c->returnValue()->setBoolean(currentSQlQuery->last()); + return true; +} +KVSO_CLASS_FUNCTION(sql,queryRecord) +{ + CHECK_QUERY_IS_INIT + KviKvsHash *pHash=new KviKvsHash(); + QSqlRecord record=currentSQlQuery->record(); + debug ("count %d",record.count()); + for(int i=0;i<record.count();i++) + { + KviKvsVariant *pValue=0; + debug ("type %s",record.value(i).typeName()); + QVariant value=record.value(i); + if (value.type()==QVariant::LongLong) pValue=new KviKvsVariant((kvs_int_t) value.toLongLong()); + else if (value.type()==QVariant::String) pValue=new KviKvsVariant(value.toString()); + else if (value.type()==QVariant::ByteArray) + { + KviKvsObjectClass * pClass = KviKvsKernel::instance()->objectController()->lookupClass("memoryBuffer"); + KviKvsVariantList params(new KviKvsVariant(QString())); + KviKvsObject * pObject = pClass->allocateInstance(0,"",c->context(),¶ms); + *((KviKvsObject_memorybuffer *)pObject)->pBuffer()=value.toByteArray(); + pValue=new KviKvsVariant(pObject->handle()); + } + else pValue=new KviKvsVariant(QString()); + pHash->set(record.fieldName(i),pValue); + } + c->returnValue()->setHash(pHash); + return true; +} + +KVSO_CLASS_FUNCTION(sql,lastError) +{ + CHECK_QUERY_IS_INIT + QString szError; + QSqlError error=currentSQlQuery->lastError(); + if (error.type()==QSqlError::StatementError) szError="SyntaxError"; + else if (error.type()==QSqlError::ConnectionError) szError="ConnectionError"; + else if (error.type()==QSqlError::TransactionError) szError="TransactionError"; + else szError="UnkonwnError"; + c->returnValue()->setString(szError); + return true; +} + + diff --git a/src/modules/objects/class_sql.h b/src/modules/objects/class_sql.h new file mode 100644 index 000000000..c25d81f7d --- /dev/null +++ b/src/modules/objects/class_sql.h @@ -0,0 +1,67 @@ +#ifndef _CLASS_SQLITE_H_ +#define _CLASS_SQLITE_H_ +//============================================================================= +// +// File : class_sqlite.h +// Creation date : Wed Gen 28 2009 21:07:55 by Alessandro Carbone +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2000-2008 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= + +#include "kvi_settings.h" +#include "kvi_string.h" +#include "kvi_pointerlist.h" +#include "kvi_kvs_variant.h" +#include "object_macros.h" +#include <QtSql> +#include <QHash> + +class KviKvsObject_sql : public KviKvsObject +{ +public: + KVSO_DECLARE_OBJECT(KviKvsObject_sql) +protected: + QSqlQuery *currentSQlQuery; + QHash<QString,QSqlQuery *> connectionsDict; + public: + QSqlQuery & getQuery() + { + //if (currentSQlQuery) return *currentSQlQuery; + return *currentSQlQuery; + }; + bool setConnection(KviKvsObjectFunctionCall *c); + bool queryResultsSize(KviKvsObjectFunctionCall *c); + bool queryNext(KviKvsObjectFunctionCall *c); + bool queryPrevious(KviKvsObjectFunctionCall *c); + bool queryFirst(KviKvsObjectFunctionCall *c); + bool queryLast(KviKvsObjectFunctionCall *c); + bool queryExec(KviKvsObjectFunctionCall *c); + bool queryRecord(KviKvsObjectFunctionCall *c); + bool queryPrepare(KviKvsObjectFunctionCall *c); + bool queryBindValue(KviKvsObjectFunctionCall *c); + bool setCurrentQuery(KviKvsObjectFunctionCall *c); + bool currentQuery(KviKvsObjectFunctionCall *c); + bool queryFinish(KviKvsObjectFunctionCall *c); + bool queryInit(KviKvsObjectFunctionCall *c); + bool closeConnection(KviKvsObjectFunctionCall *c); + bool lastError(KviKvsObjectFunctionCall *c); +}; + + +#endif //_CLASS_SQLITE_H_ diff --git a/src/modules/objects/class_tablewidget.cpp b/src/modules/objects/class_tablewidget.cpp new file mode 100644 index 000000000..00f00c2d8 --- /dev/null +++ b/src/modules/objects/class_tablewidget.cpp @@ -0,0 +1,222 @@ +//============================================================================= +// +// File : class_tablewidget.cpp +// Creation date : Wed 04 Feb 2009 09:30:05 CEST by Carbone Alessandro +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2000-2008 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= + +#include "kvi_debug.h" +#include "kvi_locale.h" +#include "kvi_error.h" +#include "kvi_iconmanager.h" +#include "kvi_file.h" + +#include "class_tablewidget.h" +#include "class_pixmap.h" +#include "class_sql.h" + #include <QTableWidget> + +/* + @doc:tablewidget + @title: + tablewidget class + @type: + class + @short: + Tablewidget widget. + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + This widget provides a table widget. + @functions: + !fn: $setText([<text:string>]) + @signals: + !sg: $clicked() + This signal is emitted by the default implementation of [classfnc]$clickEvent[/classfnc](). + +*/ + + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_tablewidget,"tablewidget","widget") + + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_tablewidget,setText) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_tablewidget,text) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_tablewidget,setIcon) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_tablewidget,setRowCount) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_tablewidget,rowCount) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_tablewidget,setColumnCount) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_tablewidget,columnCount) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_tablewidget,setHorizontalHeaderLabels) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_tablewidget,setVerticalHeaderLabels) + +KVSO_END_REGISTERCLASS(KviKvsObject_tablewidget) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_tablewidget,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_tablewidget) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_tablewidget) + +KVSO_END_DESTRUCTOR(KviKvsObject_tablewidget) + +bool KviKvsObject_tablewidget::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + SET_OBJECT(QTableWidget) + return true; +} +KVSO_CLASS_FUNCTION(tablewidget,setText) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uCol,uRow; + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,uRow) + KVSO_PARAMETER("col",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETER("col",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if(uRow>=((QTableWidget *)widget())->rowCount() || uRow>=((QTableWidget *)widget())->rowCount()) + c->warning(__tr2qs_ctx("Item out of the tablewidget size","objects")); + QTableWidgetItem *item=((QTableWidget *)widget())->item(uRow,uCol); + if(!item) + { + item=new QTableWidgetItem(); + ((QTableWidget *)widget())->setItem(uRow,uCol,item); + } + item->setText(szText); + return true; +} +KVSO_CLASS_FUNCTION(tablewidget,setIcon) +{ + kvs_uint_t uCol,uRow; + KviKvsObject *obPixmap; + kvs_hobject_t obHpixmap; + KviKvsVariant * vPixmap; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,uRow) + KVSO_PARAMETER("col",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETER("pixmap",KVS_PT_VARIANT,0,vPixmap) + KVSO_PARAMETERS_END(c) + QPixmap *pix = 0; + if(vPixmap->isHObject()) + { + vPixmap->asHObject(obHpixmap); + obPixmap=KviKvsKernel::instance()->objectController()->lookupObject(obHpixmap); + if (!obPixmap->inheritsClass("pixmap")) + { + c->warning(__tr2qs_ctx("Pixmap object or image Id required","objects")); + return true; + } + pix=((KviKvsObject_pixmap *)obPixmap)->getPixmap(); + } else { + QString szPix; + vPixmap->asString(szPix); + pix=g_pIconManager->getImage(szPix); + if(!pix) + { + c->warning(__tr2qs_ctx("Error occured: the suitable file '%Q' is not of the correct format or it is not a valid icon number.","objects"),&szPix); + return true; + } + } + QTableWidgetItem *item=((QTableWidget *)widget())->item(uRow,uCol); + if(!item) + { + item=new QTableWidgetItem(); + ((QTableWidget *)widget())->setItem(uRow,uCol,item); + } + item->setIcon(QIcon(*pix)); + return true; +} +KVSO_CLASS_FUNCTION(tablewidget,text) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uCol,uRow; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,uRow) + KVSO_PARAMETER("col",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETERS_END(c) + QTableWidgetItem *item=((QTableWidget *)widget())->item(uRow,uCol); + if(!item) c->returnValue()->setNothing(); + else c->returnValue()->setString(((QTableWidget *)widget())->item(uRow,uCol)->text()); + return true; +} +KVSO_CLASS_FUNCTION(tablewidget,setRowCount) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t iRow; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,iRow) + KVSO_PARAMETERS_END(c) + ((QTableWidget *)widget())->setRowCount(iRow); + return true; +} +KVSO_CLASS_FUNCTION(tablewidget,rowCount) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QTableWidget *)widget())->rowCount()); + return true; +} +KVSO_CLASS_FUNCTION(tablewidget,columnCount) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QTableWidget *)widget())->columnCount()); + return true; +} + +KVSO_CLASS_FUNCTION(tablewidget,setColumnCount) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t iCol; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("col",KVS_PT_UNSIGNEDINTEGER,0,iCol) + KVSO_PARAMETERS_END(c) + ((QTableWidget *)widget())->setColumnCount(iCol); + return true; +} + +KVSO_CLASS_FUNCTION(tablewidget,setHorizontalHeaderLabels) +{ + CHECK_INTERNAL_POINTER(widget()) + QStringList columns; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("labels",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,columns) + KVSO_PARAMETERS_END(c) + ((QTableWidget *)object())->setHorizontalHeaderLabels(columns); + return true; +} + + +KVSO_CLASS_FUNCTION(tablewidget,setVerticalHeaderLabels) +{ + CHECK_INTERNAL_POINTER(widget()) + QStringList columns; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("labels",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,columns) + KVSO_PARAMETERS_END(c) + debug("list count %d",columns.count()); + ((QTableWidget *)object())->setVerticalHeaderLabels(columns); + return true; +} + + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_class_tablewidget.moc" +#endif //COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/objects/class_tablewidget.h b/src/modules/objects/class_tablewidget.h new file mode 100644 index 000000000..a86a44a86 --- /dev/null +++ b/src/modules/objects/class_tablewidget.h @@ -0,0 +1,62 @@ +#ifndef _CLASS_TABLEWIDGET_H_ +#define _CLASS_TABLEWIDGET_H_ +//============================================================================= +// +// File : class_tablewidget.h +// Creation date : Wed 4 Feb 2009 09:30:05 CEST by Carbone Alessandro +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2000 Krzysztof Godlewski +// Copyright (C) 2000-2008 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= + + + +#include "class_widget.h" +#include "object_macros.h" +#include <QtSql> + +class KviKvsObject_tablewidget : public KviKvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_tablewidget) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + QSqlQueryModel *model; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool setText(KviKvsObjectFunctionCall *c); + bool text(KviKvsObjectFunctionCall *c); + bool setIcon(KviKvsObjectFunctionCall *c); + + bool setColumnCount(KviKvsObjectFunctionCall *c); + bool columnCount(KviKvsObjectFunctionCall *c); + bool setRowCount(KviKvsObjectFunctionCall *c); + bool rowCount(KviKvsObjectFunctionCall *c); + bool setHorizontalHeaderLabels(KviKvsObjectFunctionCall *c); + bool setVerticalHeaderLabels(KviKvsObjectFunctionCall *c); + //bool clickEvent(KviKvsObjectFunctionCall *c); + +protected slots: + //void slotClicked(); +}; + +#endif // !_CLASS_TABLEWIDGET_H_ diff --git a/src/modules/objects/libkviobjects.cpp b/src/modules/objects/libkviobjects.cpp index 7391ac990..1e4c5fc55 100644 --- a/src/modules/objects/libkviobjects.cpp +++ b/src/modules/objects/libkviobjects.cpp @@ -53,6 +53,7 @@ #include "class_socket.h" #include "class_spinbox.h" #include "class_tabwidget.h" +#include "class_tablewidget.h" #include "class_tbrowser.h" #include "class_toolbar.h" #include "class_toolbutton.h" @@ -65,6 +66,9 @@ #include "class_workspace.h" #include "class_wrapper.h" #include "class_xmlreader.h" +#include "class_sql.h" +#include "class_datetimeedit.h" + #include "kvi_iconmanager.h" #include "kvi_window.h" @@ -90,8 +94,7 @@ static bool objects_module_cleanup(KviModule *) // Don't attempt to change the order of these calls. // Derived classes must be unregistered before the base ones. - KviKvsObject_memorybuffer::unregisterSelf(); - + KviKvsObject_memorybuffer::unregisterSelf(); KviKvsObject_process::unregisterSelf(); KviKvsObject_ftp::unregisterSelf(); KviKvsObject_http::unregisterSelf(); @@ -131,8 +134,11 @@ static bool objects_module_cleanup(KviModule *) KviKvsObject_textbrowser::unregisterSelf(); KviKvsObject_textedit::unregisterSelf(); KviKvsObject_button::unregisterSelf(); - KviKvsObject_widget::unregisterSelf(); + KviKvsObject_datetimeedit::unregisterSelf(); + KviKvsObject_tablewidget::unregisterSelf(); + KviKvsObject_widget::unregisterSelf(); KviKvsObject_list::unregisterSelf(); + KviKvsObject_sql::unregisterSelf(); KviKvsObject_buttongroup::unregisterSelf(); return true; @@ -956,12 +962,15 @@ static bool objects_module_init(KviModule * m) KviKvsObject_buttongroup::registerSelf(); - KviKvsObject_list::registerSelf(); - KviKvsObject_widget::registerSelf(); - KviKvsObject_button::registerSelf(); + KviKvsObject_sql::registerSelf(); + KviKvsObject_list::registerSelf(); + KviKvsObject_widget::registerSelf(); + KviKvsObject_tablewidget::registerSelf(); + KviKvsObject_datetimeedit::registerSelf(); + KviKvsObject_button::registerSelf(); KviKvsObject_textedit::registerSelf(); KviKvsObject_textbrowser::registerSelf(); - KviKvsObject_checkbox::registerSelf(); + KviKvsObject_checkbox::registerSelf(); KviKvsObject_dialog::registerSelf(); KviKvsObject_groupbox::registerSelf(); KviKvsObject_label::registerSelf(); |
