summaryrefslogtreecommitdiffstats
path: root/src/modules/spaste
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 02:13:59 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 02:13:59 +0000
commita6d58bb6052ac8cb01805a48c4ad2f129126116f (patch)
treedd867a099fcbb263a8009a9fb22695b87855dad6 /src/modules/spaste
downloadkvirc-a6d58bb6052ac8cb01805a48c4ad2f129126116f.tar.gz
kvirc-a6d58bb6052ac8cb01805a48c4ad2f129126116f.zip
Added KDE3 version of kvirc
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kvirc@1095341 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/modules/spaste')
-rw-r--r--src/modules/spaste/Makefile.am24
-rw-r--r--src/modules/spaste/controller.cpp121
-rw-r--r--src/modules/spaste/controller.h59
-rw-r--r--src/modules/spaste/libkvispaste.cpp346
-rw-r--r--src/modules/spaste/libkvispaste.h13
5 files changed, 563 insertions, 0 deletions
diff --git a/src/modules/spaste/Makefile.am b/src/modules/spaste/Makefile.am
new file mode 100644
index 00000000..f1a6f719
--- /dev/null
+++ b/src/modules/spaste/Makefile.am
@@ -0,0 +1,24 @@
+###############################################################################
+# KVirc IRC client Makestr - 10.03.2002 Juanjo Álvarez <juanjux@yahoo.es>
+###############################################################################
+
+AM_CPPFLAGS = -I$(SS_TOPSRCDIR)/src/kvilib/include/ -I$(SS_TOPSRCDIR)/src/kvirc/include/ \
+-I/usr/include/kde/arts\
+$(SS_INCDIRS) $(SS_CPPFLAGS) -DGLOBAL_KVIRC_DIR=\"$(globalkvircdir)\"
+
+#ARTS_LD_FLAGS = -DPIC -fPIC
+#ARTS_C_FLAGS = -L/usr/lib -ldl -lartsc -lpthread
+pluglib_LTLIBRARIES = libkvispaste.la
+
+libkvispaste_la_LDFLAGS = -module -avoid-version $(SS_LDFLAGS) $(SS_LIBDIRS)
+
+libkvispaste_la_SOURCES = libkvispaste.cpp controller.cpp
+libkvispaste_la_LIBADD = $(SS_LIBLINK) ../../kvilib/build/libkvilib.la
+
+
+noinst_HEADERS= controller.h libkvispaste.h
+
+%.moc: %.h
+ $(SS_QT_MOC) $< -o $@
+
+controller.cpp: controller.moc
diff --git a/src/modules/spaste/controller.cpp b/src/modules/spaste/controller.cpp
new file mode 100644
index 00000000..5a132dbd
--- /dev/null
+++ b/src/modules/spaste/controller.cpp
@@ -0,0 +1,121 @@
+// File : controller.cpp
+// Creation date : Thu Apr 30 2002 17:13:12 GMT by Juanjo Álvarez
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2002 Juanjo Álvarez (juanjux@yahoo.es)
+// Copyright (C) 2002 Szymon Stefanek (kvirc@tin.it)
+//
+// 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. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+#include "controller.h"
+#include "kvi_window.h"
+#include "kvi_console.h"
+#include "kvi_mirccntrl.h"
+#include "kvi_app.h"
+#include "kvi_options.h"
+
+#include <qtimer.h>
+#include <qstringlist.h>
+#include <qclipboard.h>
+
+extern KviPointerList<SPasteController> * g_pControllerList;
+
+SPasteController::SPasteController(KviWindow * w,int id)
+ : m_pClipBuff(NULL),m_pFile(NULL),m_pId(id),m_pWindow(w)
+{
+ g_pControllerList->append(this);
+ //m_pWindow = w;
+ m_pTimer = new QTimer(this);
+}
+
+SPasteController::~SPasteController()
+{
+ g_pControllerList->removeRef(this);
+ if(m_pFile)
+ {
+ m_pFile->close();
+ delete m_pFile;
+ }
+ if(m_pTimer)
+ {
+ m_pTimer->stop();
+ delete m_pTimer;
+ }
+ if(m_pClipBuff)
+ delete m_pClipBuff;
+}
+
+bool SPasteController::pasteFileInit(QString &fileName)
+{
+ if(m_pClipBuff)return false; // can't paste a file while pasting the clipboard
+ if(m_pFile)return false; // can't paste two files at a time
+ m_pFile = new QFile(fileName);
+ if(!m_pFile->open(IO_ReadOnly))return false;
+ connect(m_pTimer,SIGNAL(timeout()),this,SLOT(pasteFile()));
+ m_pTimer->start(KVI_OPTION_UINT(KviOption_uintPasteDelay));
+ return true;
+}
+
+bool SPasteController::pasteClipboardInit(void)
+{
+ if(m_pFile)return false; // can't paste clipboard while pasting a file
+ QString tmp(g_pApp->clipboard()->text());
+ if(m_pClipBuff)
+ {
+ (*m_pClipBuff) += QStringList::split("\n",tmp,true);
+ } else {
+ m_pClipBuff = new QStringList(QStringList::split("\n",tmp,true));
+ m_clipBuffIterator = m_pClipBuff->begin();
+ }
+ connect(m_pTimer,SIGNAL(timeout()),this,SLOT(pasteClipboard()));
+ m_pTimer->start(KVI_OPTION_UINT(KviOption_uintPasteDelay));
+ return true;
+}
+
+void SPasteController::pasteFile(void)
+{
+#ifndef COMPILE_USE_QT4
+ QString line;
+ if(m_pFile->readLine(line,999) != -1)
+ {
+ if(line.isEmpty())
+ line = QChar(KVI_TEXT_RESET);
+ if( (!g_pApp->windowExists(m_pWindow)) || m_pWindow->console()->isNotConnected() )
+ {
+ m_pFile->close();
+ delete this;
+ } else m_pWindow->ownMessage(line.ascii());
+ } else { //File finished
+ m_pFile->close();
+ delete this;
+ }
+#endif
+}
+
+void SPasteController::pasteClipboard(void)
+{
+ if(m_clipBuffIterator != m_pClipBuff->end())
+ {
+ if((!g_pApp->windowExists(m_pWindow)) || m_pWindow->console()->isNotConnected() )
+ delete this;
+ else {
+ if((*m_clipBuffIterator).isEmpty())(*m_clipBuffIterator) = QChar(KVI_TEXT_RESET);
+ m_pWindow->ownMessage((*m_clipBuffIterator).ascii()); // <-- not good :/
+ ++m_clipBuffIterator;
+ }
+ } else delete this;//Clipboard finished
+}
+
+#include "controller.moc"
diff --git a/src/modules/spaste/controller.h b/src/modules/spaste/controller.h
new file mode 100644
index 00000000..55aeeaab
--- /dev/null
+++ b/src/modules/spaste/controller.h
@@ -0,0 +1,59 @@
+// File : controller.h
+// Creation date : Thu Apr 30 2002 17:13:12 GMT by Juanjo Álvarez
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2002 Juanjo Álvarez (juanjux@yahoo.es)
+// Copyright (C) 2002 Szymon Stefanek (kvirc@tin.it)
+//
+// 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. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+#ifndef SPASTE_CONTROLLER_H
+#define SPASTE_CONTROLLER_H
+
+#include "kvi_window.h"
+#include "kvi_string.h"
+
+#include <qobject.h>
+#include <qstringlist.h>
+#include <qfile.h>
+
+class SPasteController : public QObject
+{
+ Q_OBJECT
+public:
+ SPasteController(KviWindow * w,int id);
+ ~SPasteController();
+
+ //bool pasteFileInit(KviStr * fileName);
+ bool pasteFileInit(QString &fileName);
+ bool pasteClipboardInit(void);
+ int getId(void){return m_pId;};
+ KviWindow * window(void){return m_pWindow;};
+ //void stop(void);
+protected slots:
+ void pasteFile(void);
+ void pasteClipboard(void);
+
+private:
+ QStringList *m_pClipBuff;
+ QFile *m_pFile;
+ int m_pId;
+ KviWindow *m_pWindow;
+ QTimer *m_pTimer;
+ QStringList::Iterator m_clipBuffIterator;
+};
+
+#endif //SPASTE_CONTROLLER_H
+
diff --git a/src/modules/spaste/libkvispaste.cpp b/src/modules/spaste/libkvispaste.cpp
new file mode 100644
index 00000000..6b310324
--- /dev/null
+++ b/src/modules/spaste/libkvispaste.cpp
@@ -0,0 +1,346 @@
+// File : libkvispaste.cpp
+// Creation date : Thu Dec 27 2002 17:13:12 GMT by Juanjo �varez
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2002 Juanjo �varez (juanjux@yahoo.es)
+// Copyright (C) 2002 Szymon Stefanek (kvirc@tin.it)
+//
+// 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. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+
+
+#include "libkvispaste.h"
+#include "controller.h"
+
+#include "kvi_module.h"
+
+#include "kvi_fileutils.h"
+#include "kvi_app.h"
+#include "kvi_locale.h"
+
+#include "kvi_console.h"
+#include "kvi_options.h"
+#include "kvi_out.h"
+
+#include <qfile.h>
+#include <qclipboard.h>
+
+#ifndef COMPILE_ON_WINDOWS
+ #include <unistd.h>
+#endif
+
+KviPointerList<SPasteController> * g_pControllerList = 0;
+int ctrlId = 0;
+
+static SPasteController * spaste_find_controller(KviWindow * w)
+{
+ for(SPasteController * spc = g_pControllerList->first();spc;spc = g_pControllerList->next())
+ {
+ if(spc->window() == w)return spc;
+ }
+ return 0;
+}
+
+static KviWindow * spaste_kvs_find_window(QString &win, KviKvsModuleCommandCall * c)
+{
+ KviWindow * w;
+ if(!win.isEmpty())w = g_pApp->findWindow(win);
+ else w = c->window();
+ if(!w)
+ {
+ c->warning(__tr("Window with ID '%Q' not found"),&win);
+ return 0;
+ }
+ if((w->type() == KVI_WINDOW_TYPE_CHANNEL) || (w->type() == KVI_WINDOW_TYPE_QUERY) || (w->type() == KVI_WINDOW_TYPE_DCCCHAT))return w;
+ c->warning(__tr2qs("The specified window (%Q) is not a channel/query/DCC chat"),&win);
+ return 0;
+}
+//-------------------------------------------------
+/*
+ @doc: spaste.file
+ @type:
+ command
+ @title:
+ spaste.file
+ @short:
+ Sends the contents of a file to a window, with a delay between each line
+ @syntax:
+ spaste.file <filename:string> [window:string]
+ @description:
+ Sends the contents of a file to a conversation window doing a pause between each line. [br]
+ the optional window parameter must be a channel, query or DCC chat window, if [br]
+ no window is specified the text will be send to the current window.
+ @seealso:
+ [cmd]spaste.clipboard[/cmd],
+ [cmd]spaste.stop[/cmd],
+ [cmd]spaste.list[/cmd],
+ [cmd]spaste.setdelay[/cmd]
+*/
+//-------------------------------------------
+// spaste.file
+//-------------------------------------------
+
+static bool spaste_kvs_cmd_file(KviKvsModuleCommandCall * c)
+{
+ QString szFile,szWindow;
+ KVSM_PARAMETERS_BEGIN(c)
+ KVSM_PARAMETER("file name",KVS_PT_STRING,0,szFile)
+ KVSM_PARAMETER("window",KVS_PT_STRING,KVS_PF_OPTIONAL,szWindow)
+ KVSM_PARAMETERS_END(c)
+
+ KviWindow * window = spaste_kvs_find_window(szWindow,c);
+ if( (!window) || window->console()->isNotConnected())return false;
+
+ if(szFile.isEmpty() || (!KviFileUtils::fileExists(szFile.ascii())))
+ {
+ c->warning(__tr2qs("File not found or empty"));
+ return false;
+ }
+
+ QFile tmp(szFile);
+ if(!tmp.open(IO_ReadOnly)) {
+ c->warning(__tr2qs("I can't open that file"));
+ return false;
+ }
+ tmp.close();
+
+ SPasteController * controller = spaste_find_controller(window);
+ if(!controller)controller = new SPasteController(window,++ctrlId);
+ if(!controller->pasteFileInit(szFile)) {
+ c->warning(__tr2qs("Could not paste file"));
+ return false;
+ }
+ return true;
+}
+
+
+/*
+ @doc: spaste.clipboard
+ @type:
+ command
+ @title:
+ spaste.clipboard
+ @short:
+ Sends the contents of the clipboard to a window, pausing between each line
+ @syntax:
+ spaste.clipboard [window:string]
+ @description:
+ Sends the contents of the clipboard to a conversation window, with a delay between each line. [br]
+ the optional window parameter must be a channel, query or DCC chat window. [br]
+ If no window is specified, the text will be sent to the current window.
+ @seealso:
+ [cmd]spaste.file[/cmd],
+ [cmd]spaste.stop[/cmd],
+ [cmd]spaste.list[/cmd],
+ [cmd]spaste.setdelay[/cmd]
+*/
+//-------------------------------------------------
+// spaste.clipboard
+//-------------------------------------------------
+
+static bool spaste_kvs_cmd_clipboard(KviKvsModuleCommandCall * c)
+{
+ QString szWindow;
+ KVSM_PARAMETERS_BEGIN(c)
+ KVSM_PARAMETER("window",KVS_PT_STRING,KVS_PF_OPTIONAL,szWindow)
+ KVSM_PARAMETERS_END(c)
+ KviWindow * window = spaste_kvs_find_window(szWindow,c);
+ if( (!window) || window->console()->isNotConnected())return false;
+
+ SPasteController * controller = spaste_find_controller(window);
+ if(!controller)controller = new SPasteController(window,++ctrlId);
+ controller->pasteClipboardInit();
+ return true;
+}
+
+/*
+ @doc: spaste.stop
+ @type:
+ command
+ @title:
+ spaste.stop
+ @short:
+ Stops one or more slow-paste process.
+ @syntax:
+ spaste.stop [-a] [id:integer]
+ @description:
+ This commands stop one or more slow-paste processes. It can operate in three ways. The first, [br]
+ without any parameter or switch, stops all slow-paste processes running in the same window [br]
+ as the command. The second, using the -a switch, stops all slow paste processes running [br]
+ on all windows. The third form, without the switch and specifying a numerical slow paste process ID [br]
+ (which you can obtain with the [cmd]spaste.list[/cmd] command), stops only that process ID.
+ @switches:
+ !sw: -a | --all
+ Stops all slow paste processes running
+ @seealso:
+ [cmd]spaste.clipboard[/cmd],
+ [cmd]spaste.file[/cmd],
+ [cmd]spaste.list[/cmd],
+ [cmd]spaste.setdelay[/cmd]
+
+*/
+//--------------------------------------------------
+// spaste.stop
+//--------------------------------------------------
+
+static bool spaste_kvs_cmd_stop(KviKvsModuleCommandCall * c)
+{
+ kvs_int_t iId=0;
+ KVSM_PARAMETERS_BEGIN(c)
+ KVSM_PARAMETER("delay",KVS_PT_UNSIGNEDINTEGER,KVS_PF_OPTIONAL,iId)
+ KVSM_PARAMETERS_END(c)
+
+ if(c->hasSwitch('a',"all")) //Delete all spaste's
+ {
+ while(g_pControllerList->first()) delete g_pControllerList->first();
+ return true;
+ } else {
+ KviPointerListIterator<SPasteController> it(*g_pControllerList);
+ SPasteController *item;
+
+ if(!iId) //Delete all spaste's from the current window
+ {
+ if((c->window()->type() != KVI_WINDOW_TYPE_CHANNEL) && (c->window()->type() != KVI_WINDOW_TYPE_QUERY) && (c->window()->type() != KVI_WINDOW_TYPE_DCCCHAT))
+ {
+ QString szWinId = c->window()->id();
+ c->warning(__tr2qs("The specified window (%Q) is not a channel/query/dcc"),&szWinId);
+ return false;
+ } else {
+ while( (item = it.current()) != 0)
+ {
+ ++it;
+ if(kvi_strEqualCS(item->window()->id(),c->window()->id()))delete item;
+ }
+ }
+ } else //Delete the spaste with the given id
+ {
+ while( (item = it.current()) != 0)
+ {
+ ++it;
+ if(item->getId() == iId)delete item;
+ }
+ }
+ return true;
+ }
+}
+
+/*
+ @doc: spaste.list
+ @type:
+ command
+ @title:
+ spaste.list
+ @short:
+ Lists all the running spaste processes.
+ @syntax:
+ spaste.list
+ @description:
+ This command will list in the window where it is executed all the current slow-paste [br]
+ processes, their identification numbers, and the windows where they are running. [br]
+ @seealso:
+ [cmd]spaste.clipboard[/cmd],
+ [cmd]spaste.file[/cmd],
+ [cmd]spaste.stop[/cmd],
+ [cmd]spaste.setdelay[/cmd]
+*/
+//--------------------------------------------------
+// spaste.list
+//--------------------------------------------------
+
+static bool spaste_kvs_cmd_list(KviKvsModuleCommandCall * c)
+{
+ KviPointerListIterator<SPasteController> it(*g_pControllerList);
+ SPasteController *item;
+
+ while( (item = it.current()) != 0)
+ {
+ ++it;
+ QString szWinId = item->window()->id();
+ c->window()->output(KVI_OUT_NONE,__tr2qs("Slow-paste ID:%d Window:%Q"),item->getId(),&szWinId);
+ }
+ return true;
+}
+
+/*
+ @doc: spaste.setdelay
+ @type:
+ command
+ @title:
+ spaste.setdelay
+ @short:
+ Sets the delay time in miliseconds for the spaste module command delay
+ @syntax:
+ spaste.setdelay <time_in_msecs:integer>
+ @description:
+ Sets the delay time in milliseconds for the spaste module command delay.
+ @seealso:
+ [cmd]spaste.clipboard[/cmd],
+ [cmd]spaste.file[/cmd],
+ [cmd]spaste.stop[/cmd],
+ [cmd]spaste.list[/cmd]
+*/
+//-------------------------------------------------
+// spaste.setdelay
+//-------------------------------------------------
+
+
+static bool spaste_kvs_cmd_setdelay(KviKvsModuleCommandCall * c)
+{
+ kvs_int_t delay;
+ KVSM_PARAMETERS_BEGIN(c)
+ KVSM_PARAMETER("delay",KVS_PT_INTEGER,0,delay)
+ KVSM_PARAMETERS_END(c)
+ KVI_OPTION_UINT(KviOption_uintPasteDelay) = delay;
+ return true;
+}
+
+//-------------------------------------------------
+static bool spaste_module_init(KviModule * m)
+{
+ g_pControllerList = new KviPointerList<SPasteController>;
+ g_pControllerList->setAutoDelete(false);
+
+ KVSM_REGISTER_SIMPLE_COMMAND(m,"file",spaste_kvs_cmd_file);
+ KVSM_REGISTER_SIMPLE_COMMAND(m,"clipboard",spaste_kvs_cmd_clipboard);
+ KVSM_REGISTER_SIMPLE_COMMAND(m,"setdelay",spaste_kvs_cmd_setdelay);
+ KVSM_REGISTER_SIMPLE_COMMAND(m,"stop",spaste_kvs_cmd_stop);
+ KVSM_REGISTER_SIMPLE_COMMAND(m,"list",spaste_kvs_cmd_list);
+ return true;
+}
+//-------------------------------------------------
+static bool spaste_module_cleanup(KviModule *m)
+{
+ while(g_pControllerList->first()) delete g_pControllerList->first();
+ delete g_pControllerList;
+ g_pControllerList = 0;
+
+ return true;
+}
+//-------------------------------------------------
+static bool spaste_module_can_unload(KviModule *m)
+{
+ return (g_pControllerList->isEmpty());
+}
+//-------------------------------------------------
+KVIRC_MODULE(
+ "SPaste", // module name
+ "1.0.0", // module version
+ " (C) 2002 Juanjo Alvarez (juanjux@yahoo.es)", // author & (C)
+ "Delayed paste commands",
+ spaste_module_init,
+ spaste_module_can_unload,
+ 0,
+ spaste_module_cleanup
+)
diff --git a/src/modules/spaste/libkvispaste.h b/src/modules/spaste/libkvispaste.h
new file mode 100644
index 00000000..53724c2d
--- /dev/null
+++ b/src/modules/spaste/libkvispaste.h
@@ -0,0 +1,13 @@
+#ifndef KVISPASTE_H
+#define KVISPASTE_H
+
+#include "kvi_window.h"
+
+typedef struct _SPasteThreadData {
+ QString * strData;
+ KviWindow * win;
+} SPasteThreadData;
+
+
+
+#endif