diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-17 00:43:50 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-17 00:43:50 +0000 |
commit | ceea23677c61f20759ae986bd77b0d5c4d673edb (patch) | |
tree | 3fcec1702eaf9c14d1dd736e594f5df08dab4001 /kbfxlib/data | |
download | kbfx-ceea23677c61f20759ae986bd77b0d5c4d673edb.tar.gz kbfx-ceea23677c61f20759ae986bd77b0d5c4d673edb.zip |
Added old KDE3 version of kbfx
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kbfx@1091549 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kbfxlib/data')
-rw-r--r-- | kbfxlib/data/CMakeLists.txt | 48 | ||||
-rw-r--r-- | kbfxlib/data/kbfxdatagroup.cpp | 92 | ||||
-rw-r--r-- | kbfxlib/data/kbfxdatagroup.h | 100 | ||||
-rw-r--r-- | kbfxlib/data/kbfxdatagrouplist.cpp | 54 | ||||
-rw-r--r-- | kbfxlib/data/kbfxdatagrouplist.h | 52 | ||||
-rw-r--r-- | kbfxlib/data/kbfxdatasource.cpp | 89 | ||||
-rw-r--r-- | kbfxlib/data/kbfxdatasource.h | 151 | ||||
-rw-r--r-- | kbfxlib/data/kbfxdatastack.cpp | 84 | ||||
-rw-r--r-- | kbfxlib/data/kbfxdatastack.h | 64 | ||||
-rw-r--r-- | kbfxlib/data/kbfxplasmadataplugin.cpp | 29 | ||||
-rw-r--r-- | kbfxlib/data/kbfxplasmadataplugin.h | 29 | ||||
-rw-r--r-- | kbfxlib/data/kbfxplasmapluginloader.cpp | 161 | ||||
-rw-r--r-- | kbfxlib/data/kbfxplasmapluginloader.h | 79 | ||||
-rw-r--r-- | kbfxlib/data/kbfxplugin.cpp | 115 | ||||
-rw-r--r-- | kbfxlib/data/kbfxplugin.h | 74 |
15 files changed, 1221 insertions, 0 deletions
diff --git a/kbfxlib/data/CMakeLists.txt b/kbfxlib/data/CMakeLists.txt new file mode 100644 index 0000000..676ef78 --- /dev/null +++ b/kbfxlib/data/CMakeLists.txt @@ -0,0 +1,48 @@ +SET(libkbfxdatasrc + kbfxdatagroup.cpp + kbfxdatagrouplist.cpp + kbfxdatasource.cpp + kbfxdatastack.cpp + kbfxplasmadataplugin.cpp + kbfxplasmapluginloader.cpp + kbfxplugin.cpp + ) + +FILE(GLOB HEADERS *.h) + +IF (NOT USE_KDE4) + KDE3_AUTOMOC(${libkbfxdatasrc}) + + ADD_LIBRARY(kbfxdata SHARED ${libkbfxdatasrc}) + SET_TARGET_PROPERTIES(kbfxdata + PROPERTIES + COMPILE_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) + # SET_TARGET_PROPERTIES(kbfxdata PROPERTIES + # SOVERSION ${LIB_MAJOR} + # VERSION ${APPLICATION_VERSION}) + TARGET_LINK_LIBRARIES(kbfxdata + ${QT_AND_KDECORE_LIBS} + ${KDE3_KIO_LIBRARY} + ${KDE3_UI_LIBRARY} + ${KDE3_KHTML_LIBRARY} + ${M_LIBRARY} + ) + + KDE3_INSTALL_LIBTOOL_FILE(kbfxdata ${LIB_INSTALL_DIR}) +ELSE (NOT USE_KDE4) + KDE4_AUTOMOC(${libkbfxdatasrc}) + + KDE4_ADD_LIBRARY(kbfxdata SHARED ${libkbfxdatasrc}) + TARGET_LINK_LIBRARIES(kbfxdata + ${KDE4_KDECORE_LIBS} + ${KDE4_KIO_LIBS} + ${KDE4_KDEUI_LIBS} + ${KDE4_KHTML_LIBS} + ${M_LIBRARY} + ) + + KDE4_INSTALL_LIBTOOL_FILE(kbfxdata ${LIB_INSTALL_DIR}) +ENDIF (NOT USE_KDE4) + +INSTALL(TARGETS kbfxdata DESTINATION ${LIB_INSTALL_DIR}) +INSTALL(FILES ${HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/kbfx/data) diff --git a/kbfxlib/data/kbfxdatagroup.cpp b/kbfxlib/data/kbfxdatagroup.cpp new file mode 100644 index 0000000..5c097a6 --- /dev/null +++ b/kbfxlib/data/kbfxdatagroup.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <siraj@kdemail.net> + * PhobosK <phobosk@mail.kbfx.org> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxdatagroup.h" + +KbfxDataGroup::KbfxDataGroup() +{ + m_name = "Uknown Group"; + m_count = 0; +} + +KbfxDataGroup::~KbfxDataGroup() +{ + Data::Iterator it; + for ( it = m_data.begin();it!=m_data.end();++it ) + { + delete it.data(); + m_data.remove ( it ); + //delete *it; + } + m_data.clear(); +} + +KbfxDataSource::DataSourceList +KbfxDataGroup::lookup ( QString str ) +{ +//static KbfxDataGroup * _matching = new KbfxDataGroup(); + KbfxDataSource::DataSourceList _matching; + Data::Iterator it; + for ( it = m_data.begin();it!=m_data.end();++it ) + { + if ( ( *it )->lookup ( str ) == true ) + { + _matching.prepend ( * ( *it ) ); + } + } + + return _matching; +} + +void +KbfxDataGroup::addItem ( KbfxDataSource * item ) +{ + if ( item == 0 ) + return ; + m_data[item->name() ] = item; + m_index[m_count] = item; + m_count++; + +// qDebug("KbfxDataGroup.cpp::addItem("+item->name()+")"); +} + +KbfxDataSource* +KbfxDataGroup::itemAt(int index) +{ + if ( index < 0 || index > m_count) + return new KbfxDataSource(); + else + return m_index[index]; +} + + +KbfxDataSource * +KbfxDataGroup::getItem ( QString name ) +{ + return m_data[name]; +} + +KbfxDataGroup::Data +KbfxDataGroup::getData() +{ + return m_data; +} + diff --git a/kbfxlib/data/kbfxdatagroup.h b/kbfxlib/data/kbfxdatagroup.h new file mode 100644 index 0000000..7587502 --- /dev/null +++ b/kbfxlib/data/kbfxdatagroup.h @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <siraj@kdemail.net> + * PhobosK <phobosk@mail.kbfx.org> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_DATA_GROUP_H +#define KBFX_DATA_GROUP_H + +#include <qmap.h> +#include <qstringlist.h> +#include "kbfxdatasource.h" + +class KbfxDataGroup +{ + + public: + typedef QMap<QString,KbfxDataSource*> Data; + typedef QMap<int,KbfxDataSource*> Index; + + /** + * Construts a new data group and initialzes the group + * @return Constructs a new Datagroup + */ + KbfxDataGroup(); + /** + * De-allocates and frees the meomery when destroyed + * @return + */ + ~KbfxDataGroup(); + /** + * Adds a new DataSource to the Group + * null pointers and invalid datasources are handled + * internally no manal checking is needed + * @param item A pointer to a datasource valid or invalid + */ + void addItem ( KbfxDataSource * item ); + /** + * Sets a proper Name to the group. The default will be set to + * "Unknown Group" . it is recomended that a name is always set + * @param name The name that should be give to the group + */ + void setName ( QString name ) {m_name = name;} + /** + * To access a datasource give the name of the datasource + * @param The name othe datasource + * @return pointer to a valid datasource + */ + KbfxDataSource * getItem ( QString ); + /** + * use this to get all the items inside the datagroup + * @return a copy of the data Map (QMap<QString,KbfxDataSource*>) + */ + Data getData(); + /** + * searches and returns the list of matching datasources + * @param keyword to search for + * @return list of matching datasources + */ + KbfxDataSource::DataSourceList lookup ( QString ); + /** + * The name of the group + * @return Name of the group + */ + QString name() {return m_name;} + /** + * The number of datasources inside the datagroup + * @return number of datasources + */ + int count() {return m_count;} + /** + * + * + * + */ + KbfxDataSource * itemAt(int index); + + private: + Data m_data; + QString m_name; + int m_count; + Index m_index; +}; + +#endif diff --git a/kbfxlib/data/kbfxdatagrouplist.cpp b/kbfxlib/data/kbfxdatagrouplist.cpp new file mode 100644 index 0000000..5f89b5f --- /dev/null +++ b/kbfxlib/data/kbfxdatagrouplist.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <siraj@kdemail.net> + * PhobosK <phobosk@mail.kbfx.org> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxdatagrouplist.h" + +KbfxDataGroupList::KbfxDataGroupList() +{ + m_name="Unset"; + m_iconPath= ""; + m_count = 0; +//m_groupList.setAutoDelete(true); +} + +KbfxDataGroupList::~KbfxDataGroupList() +{ +} + +void +KbfxDataGroupList::addGroup ( KbfxDataGroup * group ) +{ + + + for ( int i =0; i < ( int ) m_groupList.count();i++ ) + { +// qDebug("Curent loop + "+m_groupList.at(i)->name()+"adding "+group->name()); + if ( m_groupList.at ( i ) == group ) + { + return ; + } + } +//above is to save from bad plugins + + m_groupList.append ( group ); + m_count++; +} + diff --git a/kbfxlib/data/kbfxdatagrouplist.h b/kbfxlib/data/kbfxdatagrouplist.h new file mode 100644 index 0000000..711b7af --- /dev/null +++ b/kbfxlib/data/kbfxdatagrouplist.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <siraj@kdemail.net> + * PhobosK <phobosk@mail.kbfx.org> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_DATA_GROUP_LIST_H +#define KBFX_DATA_GROUP_LIST_H + +#include <qptrlist.h> +#include "kbfxdatagroup.h" + +class KbfxDataGroupList +{ + public: + typedef QPtrList<KbfxDataGroup> GroupList; + KbfxDataGroupList(); + ~KbfxDataGroupList(); + //in + void addGroup ( KbfxDataGroup * group ); + void setName ( QString name ) { m_name = name;} + void setIcon ( QString path ) { m_iconPath = path;} + //out + QString name() {return m_name;} + GroupList getGroup() { return m_groupList;} + QString iconPath() { return m_iconPath;} + + int count() {return m_count;} + + private: + QString m_name; + QString m_iconPath; + GroupList m_groupList; + int m_count; +}; + +#endif diff --git a/kbfxlib/data/kbfxdatasource.cpp b/kbfxlib/data/kbfxdatasource.cpp new file mode 100644 index 0000000..8a44478 --- /dev/null +++ b/kbfxlib/data/kbfxdatasource.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <siraj@kdemail.net> + * PhobosK <phobosk@mail.kbfx.org> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxdatasource.h" +#include <kdesktopfile.h> +#include <kapplication.h> +#include <krun.h> + +KbfxDataSource::KbfxDataSource() +{ + m_type = NONDESKTOP; + m_keyWords=""; + m_command=""; + m_desktopPath="none"; + m_contentPath = "none"; +} + +KbfxDataSource::~KbfxDataSource() +{ +} + +bool +KbfxDataSource::lookup ( QString str ) +{ + if ( str.isNull() ) + return false; + + QString _searchStr = m_text+m_comment+m_description+m_keyWords; + + + if ( _searchStr.contains ( str,false ) > 0 ) + return true; + + return false; +} + +void +KbfxDataSource::loadDesktopFile() +{ + KDesktopFile * file = new KDesktopFile ( m_desktopPath ); + m_text = file->readName(); + m_comment= file->readComment(); + m_iconPath = file->readIcon(); + m_command = file->readEntry ( "Exec","none" ); + m_description = file->readGenericName () +file->readEntry ( "Categories","Application" ); + + setContentPath ( m_desktopPath ); + delete file; + +} + + +void +KbfxDataSource::exec() +{ + + if ( type() == KbfxDataSource::DESKTOP ) + { + QCString dcop; + int pid; + QString m_error; + KApplication::startServiceByDesktopPath ( desktopFile(), + QString::null, &m_error,&dcop,&pid,"",true ); + } + + else + { + KRun::runCommand ( m_command ); + } +} + diff --git a/kbfxlib/data/kbfxdatasource.h b/kbfxlib/data/kbfxdatasource.h new file mode 100644 index 0000000..aba89ad --- /dev/null +++ b/kbfxlib/data/kbfxdatasource.h @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <siraj@kdemail.net> + * PhobosK <phobosk@mail.kbfx.org> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_DATA_SOURCE_H +#define KBFX_DATA_SOURCE_H + +#include <qvaluelist.h> +#include <qstring.h> + +class KbfxDataSource +{ + + + public: + typedef enum + { DESKTOP = 0, NONDESKTOP } Type; + typedef QValueList < KbfxDataSource > DataSourceList; + /** + * Constructs a new DataSource. Data source is a simple class that holds + * a .desktop file and also you can include a custom commmand that can be + * exectuted + * @return a pointer to a new data source + */ + KbfxDataSource (); + virtual ~ KbfxDataSource (); + + /** + * Sets the name of a data source and should not be used if your dara is + * a desktop file use KbfxDataSource::setDesktopPath() functions instead + * @param name should be the name of the data source + */ + void setName ( QString name ) + { + m_text = name; + } + /** + * Sets the desktop file of for the data source. Note that u do not have to check + * parameters such as if the the desktop is kiosk allowed. the this function internally + * abstracts such functions. + * @param path should be the absolute path of a valid desktop file + */ + void setDesktopPath ( QString path ) + { + m_desktopPath = path; + m_type = DESKTOP; + loadDesktopFile (); + } + + virtual void setCommand ( QString cmd ) + { + m_command = cmd; + } + + + void setContentPath ( QString path ) + { + m_contentPath = path; + } + QString contentPath () + { + return m_contentPath; + } + + virtual void setType ( Type t ) + { + m_type = t; + } + + virtual void exec (); + + void setComment ( QString comment ) + { + m_comment = comment; + }; + + void setDescription ( QString desc ) + { + m_description = desc; + } + + void setIconPath ( QString path ) + { + m_iconPath = path; + } + + QString desktopFile () + { + return m_desktopPath; + } + //out + QString name () + { + return m_text; + } + QString icon () + { + return m_iconPath; + }; + QString command () + { + return m_command; + } + Type type () + { + return m_type; + } + /** + * Use this function to get the comment of the a data soruce. this + * functio will NOT return NULL so no checking needed + * @return the comment of the data source or empty string + */ + QString comment () + { + return m_comment; + } + bool lookup ( QString str ); + private: +//TODO +//MOve to private D + void loadDesktopFile (); + QString m_text; + QString m_desktopPath; + QString m_command; + QString m_iconPath; + QString m_comment; + QString m_description; + QString m_keyWords; + Type m_type; + QString m_contentPath; + + +}; +#endif diff --git a/kbfxlib/data/kbfxdatastack.cpp b/kbfxlib/data/kbfxdatastack.cpp new file mode 100644 index 0000000..2d84e02 --- /dev/null +++ b/kbfxlib/data/kbfxdatastack.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <siraj@kdemail.net> + * PhobosK <phobosk@mail.kbfx.org> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxdatastack.h" + +KbfxDataStack::KbfxDataStack() +{ + m_nameList.append ( "" ); + m_name = "Unset"; + m_count = 0; +} + +KbfxDataStack::~KbfxDataStack() +{ +//TODO: empty the list +} + +void +KbfxDataStack::addGroupList ( KbfxDataGroupList * list ) +{ + m_stack[list->name() ]=list; + m_nameList.append ( list->name() ); + m_dict[list->name() ]=m_count; + + KbfxPlasmaCanvasStackData stackinfo; + stackinfo.name = list->name(); + stackinfo.icon = list->iconPath(); + m_dataDict[m_count] = stackinfo; + + m_count++; + +} +QStringList +KbfxDataStack::getStackIndex() +{ + return m_nameList; +} + +KbfxDataGroupList * +KbfxDataStack::getStack ( QString name ) +{ + + + if ( m_nameList.contains ( name ) >0 ) + return m_stack[name]; + else + { + return NULL; + } +} + + +QString +KbfxDataStack::getSubGroupName ( uint id ) +{ + + Dict::Iterator it; + for ( it=m_dict.begin();it!=m_dict.end();++it ) + { + if ( it.data() == id ) + return it.key(); + + } + return QString ( "Empty" ); +} + diff --git a/kbfxlib/data/kbfxdatastack.h b/kbfxlib/data/kbfxdatastack.h new file mode 100644 index 0000000..6d65810 --- /dev/null +++ b/kbfxlib/data/kbfxdatastack.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <siraj@kdemail.net> + * PhobosK <phobosk@mail.kbfx.org> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_DATA_STACK_H +#define KBFX_DATA_STACK_H + +#include <qmap.h> +#include <qstring.h> +#include <qstringlist.h> +#include "kbfxdatagrouplist.h" +#include "kbfxplasmacanvasstackdata.h" //TODO:change the name here + +class KbfxDataStack +{ + + public: + typedef QMap<QString,KbfxDataGroupList*> StackMap; + typedef QMap<QString,uint> Dict; + typedef QMap<int,KbfxPlasmaCanvasStackData> DataDict; + + KbfxDataStack(); + ~KbfxDataStack(); + void setName ( QString name ) { m_name=name;} + void addGroupList ( KbfxDataGroupList * list ); + //out + KbfxDataGroupList * getGroupList ( QString name ); + QStringList getStackIndex(); + KbfxDataGroupList * getStack ( QString name ); + + Dict getDict() {return m_dict;} + DataDict getDataDict() { return m_dataDict;} + QString name() {return m_name;} + uint getIndex ( QString name ) { return m_dict[name];} + QString getSubGroupName ( uint id ); + int count() {return m_count;} + private: + StackMap m_stack; + QStringList m_nameList; + QString m_name; + Dict m_dict; + DataDict m_dataDict; + uint m_count; + +}; + +#endif diff --git a/kbfxlib/data/kbfxplasmadataplugin.cpp b/kbfxlib/data/kbfxplasmadataplugin.cpp new file mode 100644 index 0000000..d237d3a --- /dev/null +++ b/kbfxlib/data/kbfxplasmadataplugin.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <siraj@kdemail.net> + * PhobosK <phobosk@mail.kbfx.org> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxplasmadataplugin.h" + +KbfxPlasmaCanvasStack * view() +{ + + return NULL; + +} diff --git a/kbfxlib/data/kbfxplasmadataplugin.h b/kbfxlib/data/kbfxplasmadataplugin.h new file mode 100644 index 0000000..82a812b --- /dev/null +++ b/kbfxlib/data/kbfxplasmadataplugin.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <siraj@kdemail.net> + * PhobosK <phobosk@mail.kbfx.org> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxplasmacanvasstack.h" + + +extern "C" +{ + KbfxPlasmaCanvasStack * view(); +} + diff --git a/kbfxlib/data/kbfxplasmapluginloader.cpp b/kbfxlib/data/kbfxplasmapluginloader.cpp new file mode 100644 index 0000000..ebc992a --- /dev/null +++ b/kbfxlib/data/kbfxplasmapluginloader.cpp @@ -0,0 +1,161 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <siraj@kdemail.net> + * PhobosK <phobosk@mail.kbfx.org> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include <config.h> + +#include "kbfxplasmapluginloader.h" +#include <qdir.h> +#include <qfileinfo.h> +#include <kstandarddirs.h> +#include <kdebug.h> + +KbfxPlasmaPluginLoader::KbfxPlasmaPluginLoader() +{ + m_plugin = 0; + init(); + +} + + +void +KbfxPlasmaPluginLoader::init() +{ + + QString libprefix = locate ( "lib","libkbfxdata.so" ); + libprefix.remove ( "libkbfxdata.so" ); +// QString libprefix = KBFX_LIB_INSTALL_DIR ; + kdDebug() << "KBFX plugins lib is: " << libprefix << endl; + QDir * _dir = new QDir ( libprefix+"/kbfx/plugins/" ); + QStringList plugins; + _dir->setFilter ( QDir::Files ); + _dir->setNameFilter ( "*.so" ); + if ( !_dir->exists() ) + { + kdDebug() << "Invalid Plugin Prefix: " << libprefix << "/kbfx/plugins/" << endl; + delete _dir; + return ;//QStringList("No Plugins found: Error in default Paths.Contact Package Manager"); + } + + const QFileInfoList *list = _dir->entryInfoList(); + QFileInfoListIterator it ( *list ); + QFileInfo *fi=0; + int _index =0; + while ( ( fi = it.current() ) != 0 ) + { + QString * path = new QString ( libprefix+"/kbfx/plugins/"+fi->fileName() ); + QLibrary * _l = new QLibrary ( *path ); + + typedef QString ( *getName ) (); + getName nameFunc; + nameFunc = ( getName ) _l->resolve ( "name" ); + if ( nameFunc ) + { + pluginMap() [nameFunc() ] = new KbfxPlugin ( nameFunc(),*path,_index++ ); + } + ++it; + _l->unload(); + delete _l; + delete path; + } + + delete _dir; +} + + +KbfxPlasmaPluginLoader::~KbfxPlasmaPluginLoader() +{ + // if(m_plugin!=0) +// delete m_plugin; + + // PluginMap::Iterator it; + // for ( it = pluginMap().begin(); it != pluginMap().end(); ++it ) { + // delete it.data(); + // pluginMap().remove(it); + // } + + +} + +KbfxDataStack * +KbfxPlasmaPluginLoader::getView ( QString name ) +{ + PluginMap::Iterator it; + for ( it = pluginMap().begin(); it != pluginMap().end(); ++it ) + { + pluginMap().remove ( it ); + } + init(); + KbfxDataStack * stack = pluginMap() [name]->data(); + + if (stack == 0 ) { + return new KbfxDataStack(); + } + + return stack; +} + +KbfxDataGroup * +KbfxPlasmaPluginLoader::search ( QString pname,QString keyword ) +{ + if ( pname == NULL ) + return NULL; + + KbfxDataGroup * group = pluginMap() [pname]->search ( keyword ); + if ( group == NULL ) + { + kdDebug() << "KbfxPlasmaaPluginLoader:109:Null pointer" << endl; + return NULL; + } + + return group; + +} + + +KbfxPlasmaPluginLoader::PluginMap& +KbfxPlasmaPluginLoader::pluginMap() +{ + static PluginMap * map = 0; + if ( !map ) + map = new PluginMap(); + return *map; +} + + + + +QStringList +KbfxPlasmaPluginLoader::scanPlugins() +{ + + init(); + QStringList plugins; + PluginMap::Iterator it; + + for ( it = pluginMap().begin(); it != pluginMap().end();++it ) + { + if ( it.data()->status() == false ) + plugins.append ( it.data()->name() ); + } + return plugins; +} + +#include "kbfxplasmapluginloader.moc" diff --git a/kbfxlib/data/kbfxplasmapluginloader.h b/kbfxlib/data/kbfxplasmapluginloader.h new file mode 100644 index 0000000..2ae2f54 --- /dev/null +++ b/kbfxlib/data/kbfxplasmapluginloader.h @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <siraj@kdemail.net> + * PhobosK <phobosk@mail.kbfx.org> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_PLASMA_PLUGIN_LOADER_H +#define KBFX_PLASMA_PLUGIN_LOADER_H + +#include <qlibrary.h> +#include "kbfxplasmacanvasstack.h" +#include "kbfxdatastack.h" +#include "kbfxplugin.h" +#include <qcanvas.h> + +class KbfxPlasmaPluginLoader:public QObject +{ + Q_OBJECT + + public: + typedef QMap<QString,KbfxPlugin*> PluginMap; + + /** + * + * @return + */ + KbfxPlasmaPluginLoader(); + /** + * + * @return + */ + ~KbfxPlasmaPluginLoader(); + /** + * + * @param name + * @return + */ + KbfxDataStack * getView ( QString name ); + /* + look for all installed Plugins. returns a list of installed plugins + */ + static QStringList scanPlugins(); + + /** + * Calls the search function of a given plugin and returns the result + * @param pluginName The name of the plugin to call + * @param keyword the keyword to pass to the plugin + * @return a valid KbfxDataGroup or -1 + */ + static KbfxDataGroup * search ( QString pluginName,QString keyword ); + + protected: + static void init(); + + private: + + QLibrary * m_plugin; + static PluginMap& pluginMap(); + QString m_prefix; + + +}; + +#endif diff --git a/kbfxlib/data/kbfxplugin.cpp b/kbfxlib/data/kbfxplugin.cpp new file mode 100644 index 0000000..ae53d67 --- /dev/null +++ b/kbfxlib/data/kbfxplugin.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <siraj@kdemail.net> + * PhobosK <phobosk@mail.kbfx.org> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxplugin.h" + +KbfxPlugin::KbfxPlugin ( QString name,QString lib,uint id ) +{ + m_name = name; + m_libName = lib; + m_id = id; + m_loaded = false; +} + +KbfxPlugin::KbfxPlugin() +{ +} + +KbfxPlugin::~KbfxPlugin() +{ +// delete [] m_name; +// delete [] m_libName; +} + +QString +KbfxPlugin::name() +{ + return m_name; +} + +QString +KbfxPlugin::libName() +{ + return m_libName; +} + +uint +KbfxPlugin::id() +{ + return m_id; +} + +bool +KbfxPlugin::status() +{ + return m_loaded; +} + +KbfxDataStack * +KbfxPlugin::data() +{ + typedef KbfxDataStack * ( *KbfxPluginView ) (); + KbfxDataStack * m_stack =0; + KbfxPluginView m_hook; + QLibrary * m_plugin = new QLibrary ( m_libName ); + + if ( m_plugin == NULL ) + return new KbfxDataStack(); + + m_hook = ( KbfxPluginView ) m_plugin->resolve ( "view" ); + m_stack = m_hook(); + m_plugin->unload(); + delete m_plugin; + + if ( m_stack != NULL ) + return m_stack; + else + return new KbfxDataStack(); +} + +KbfxDataGroup * +KbfxPlugin::search ( QString keyword ) +{ + if ( keyword == 0 ) + return NULL;//new KbfxDataGroup(); + + if ( keyword.isNull() ) + return NULL;//KbfxDataGroup(); + + + typedef KbfxDataGroup * ( *KbfxPluginSearch ) ( QString key ); + KbfxDataGroup * m_group =0; + KbfxPluginSearch m_hook; + QLibrary * m_plugin = new QLibrary ( m_libName ); + m_hook = ( KbfxPluginSearch ) m_plugin->resolve ( "search" ); + m_group = m_hook ( keyword ); + m_plugin->unload(); + delete m_plugin; + if ( m_group != NULL ) + { + // qDebug("KbfxPlugin():search():103:return Valid Group "+m_group->name()); + return m_group; + } + else return NULL; +} + + +#include "kbfxplugin.moc" diff --git a/kbfxlib/data/kbfxplugin.h b/kbfxlib/data/kbfxplugin.h new file mode 100644 index 0000000..5868d14 --- /dev/null +++ b/kbfxlib/data/kbfxplugin.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <siraj@kdemail.net> + * PhobosK <phobosk@mail.kbfx.org> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_PLUGIN_H +#define KBFX_PLUGIN_H +//#include "kbfxplasmacanvasstack.h" +#include "kbfxdatastack.h" +#include <qobject.h> +#include <qstring.h> +#include <qlibrary.h> +/** +This class reprecentes a plugin +written for kbfx menu this +will be passed between the life time +of the menu +**/ + + +class KbfxPlugin:public QObject +{ + + Q_OBJECT + public: + + KbfxPlugin(); + KbfxPlugin ( QString Name,QString lib,uint id ); + ~KbfxPlugin(); + + void setStatus ( bool ); + + QString name(); + QString libName(); + uint id(); + bool status(); +// KbfxPlasmaCanvasStack * data(); + KbfxDataStack * data(); + KbfxDataGroup * search ( QString keyword ); + +// KbfxDataStack * data(); + + public slots: + void reload() {} + signals: + void loadComplete(); + + private: + QString m_name; + QString m_libName; + uint m_id; +// KbfxPlasmaCanvasStack * m_data; + KbfxDataStack m_data_R; +// QCanvas * m_canvas; + bool m_loaded; +}; + +#endif |