aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/kvirc/kvs/kvi_kvs_coresimplecommands_af.cpp45
-rw-r--r--src/kvirc/kvs/kvi_kvs_coresimplecommands_mr.cpp50
-rw-r--r--src/modules/CMakeLists.txt2
-rw-r--r--src/modules/popup/CMakeLists.txt11
-rw-r--r--src/modules/popup/libkvipopup.cpp200
5 files changed, 230 insertions, 78 deletions
diff --git a/src/kvirc/kvs/kvi_kvs_coresimplecommands_af.cpp b/src/kvirc/kvs/kvi_kvs_coresimplecommands_af.cpp
index d557eba8a..3a377b304 100644
--- a/src/kvirc/kvs/kvi_kvs_coresimplecommands_af.cpp
+++ b/src/kvirc/kvs/kvi_kvs_coresimplecommands_af.cpp
@@ -36,7 +36,6 @@
#include "kvi_scriptbutton.h"
#include "kvi_iconmanager.h"
-#include "kvi_kvs_popupmanager.h"
#include "kvi_kvs_eventmanager.h"
#include "kvi_kvs_kernel.h"
#include "kvi_kvs_object_controller.h"
@@ -924,48 +923,26 @@ namespace KviKvsCoreSimpleCommands
!sw: -d | --deep
Search the whole popup tree instead of only the first level
@description:
- Deletes the item specified by <id> from the poup <popupname>.
- If the -d flag is specified then the item with the specified
- <id> is searched in the whole popup tree (containing submenus)
- otherwise only the first level is searched. [br]
- If the -q flag is specified, the command does not complain
- about non-existent items or popup menus.[br]
- See [cmd]defpopup[/cmd] for more information.[br]
+ This is an internal alias for [cmd]popup.delitem[/cmd].[br]
+ This function is deprecated and its use is discouraged.
@seealso:
- [cmd]defpopup[/cmd], [cmd]popup[/cmd]
+ [cmd]popup.delitem[/cmd]
*/
- // FIXME: #warning "Separator should have the expression too ?"
-
KVSCSC(delpopupitem)
{
- QString szPopupName,szItemId;
+ QString szParams;
KVSCSC_PARAMETERS_BEGIN
- KVSCSC_PARAMETER("popupname",KVS_PT_NONEMPTYSTRING,0,szPopupName)
- KVSCSC_PARAMETER("item_id",KVS_PT_NONEMPTYSTRING,0,szItemId)
+ KVSCSC_PARAMETER("params",KVS_PT_STRING,KVS_PF_OPTIONAL | KVS_PF_APPENDREMAINING,szParams)
KVSCSC_PARAMETERS_END
- KviKvsPopupMenu * p = KviKvsPopupManager::instance()->lookup(szPopupName);
- if(!p)
- {
- if(!KVSCSC_pSwitches->find('q',"quiet"))
- KVSCSC_pContext->warning(__tr2qs_ctx("Inexisting popup \"%Q\"","kvs"),&szPopupName);
- return true;
- }
-
- if(p->isLocked())
- {
- KVSCSC_pContext->error(__tr2qs_ctx("Popup menu self-modification is not allowed (the popup is probably open)","kvs"));
- return false;
- }
-
- if(!p->removeItemByName(szItemId,KVSCSC_pSwitches->find('d',"deep")))
- {
- if(!KVSCSC_pSwitches->find('q',"quiet"))
- KVSCSC_pContext->warning(__tr2qs_ctx("The menu item with id \"%Q\" does not exist in popup \"%Q\"","kvs"),&szItemId,&szPopupName);
- }
+ // We just alias the popup.delitem function
+ QString szSwitches="";
+ if(KVSCSC_pSwitches->find('d',"deep"))szSwitches.append("-d ");
+ if(KVSCSC_pSwitches->find('q',"quiet"))szSwitches.append("-q ");
- KviKvsPopupManager::instance()->emitRefresh(szPopupName);
+ KviKvsScript s("delpopupitem","popup.delitem " + szSwitches + szParams);
+ s.run(KVSCSC_pContext->window());
return true;
}
diff --git a/src/kvirc/kvs/kvi_kvs_coresimplecommands_mr.cpp b/src/kvirc/kvs/kvi_kvs_coresimplecommands_mr.cpp
index 6b4b31899..ad332979a 100644
--- a/src/kvirc/kvs/kvi_kvs_coresimplecommands_mr.cpp
+++ b/src/kvirc/kvs/kvi_kvs_coresimplecommands_mr.cpp
@@ -850,59 +850,23 @@ namespace KviKvsCoreSimpleCommands
KVSCSC(popup)
{
- QString szPopupName;
+ QString szParams;
KVSCSC_PARAMETERS_BEGIN
- KVSCSC_PARAMETER("popup_name",KVS_PT_NONEMPTYSTRING,0,szPopupName)
+ KVSCSC_PARAMETER("params",KVS_PT_STRING,KVS_PF_OPTIONAL | KVS_PF_APPENDREMAINING,szParams)
KVSCSC_PARAMETERS_END
- // copy parameters
- KviKvsVariantList * pPopupParams = new KviKvsVariantList();
- KVSCSC_pParams->first();
- while(KviKvsVariant * v = KVSCSC_pParams->next())pPopupParams->append(new KviKvsVariant(*v));
-
- KviKvsPopupMenu * pMenu = KviKvsPopupManager::instance()->lookup(szPopupName);
-
- if(!pMenu)
- {
- delete pPopupParams;
- pPopupParams = 0;
- KVSCSC_pContext->error(__tr2qs_ctx("Popup %Q is not defined","kvs"),&szPopupName);
- return false;
- }
-
- if(pMenu->isLocked())
- {
- delete pPopupParams;
- pPopupParams = 0;
- KVSCSC_pContext->error(__tr2qs_ctx("A popup menu cannot be popped up twice","kvs"));
- return false;
- }
-
- QPoint pnt = QCursor::pos();
-
+ // We just alias the popup.show function
+ QString szSwitches="";
KviKvsVariant * pCoords = KVSCSC_pSwitches->find('p',"point");
if(pCoords)
{
QString szCoords;
pCoords->asString(szCoords);
-
- int idx = szCoords.indexOf(',');
- bool bCoordsOk = true;
- if(idx == -1)bCoordsOk = false;
- else {
- QString szX = szCoords.left(idx);
- szCoords.remove(0,idx + 1);
- bool bOk1,bOk2;
- int iX = szX.toInt(&bOk1);
- int iY = szCoords.toInt(&bOk2);
- if(bOk1 && bOk2)pnt = QPoint(iX,iY);
- else bCoordsOk = false;
- }
-
- if(!bCoordsOk)KVSCSC_pContext->warning(__tr2qs_ctx("Invalid syntax for screen coordinates, using cursor position","kvs"));
+ szSwitches.append(QString("-p=\"%1\" ").arg(szCoords));
}
- pMenu->doPopup(pnt,KVSCSC_pContext->window(),pPopupParams);
+ KviKvsScript s("popup","popup.show " + szSwitches + szParams);
+ s.run(KVSCSC_pContext->window());
return true;
}
diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt
index ae31ee9c2..c74475eb5 100644
--- a/src/modules/CMakeLists.txt
+++ b/src/modules/CMakeLists.txt
@@ -31,7 +31,7 @@ SUBDIRS(
mask math mediaplayer mircimport my
notifier
objects options
- perlcore popupeditor proxydb pythoncore
+ perlcore popup popupeditor proxydb pythoncore
raweditor regchan reguser rijndael rot13
serverdb setup sharedfile sharedfileswindow snd socketspy spaste str system
texticons term theme tip tmphighlight toolbar toolbareditor torrent trayicon
diff --git a/src/modules/popup/CMakeLists.txt b/src/modules/popup/CMakeLists.txt
new file mode 100644
index 000000000..61a3892c0
--- /dev/null
+++ b/src/modules/popup/CMakeLists.txt
@@ -0,0 +1,11 @@
+# CMakeLists for src/modules/popup
+
+SET(kvipopup_SRCS
+ libkvipopup.cpp
+)
+
+# After this call, files will be moc'ed to moc_kvi_*.cpp
+QT4_WRAP_CPP(kvipopup_MOC_SRCS ${kvipopup_MOC_HDRS})
+
+SET(kvi_module_name kvipopup)
+INCLUDE(${CMAKE_SOURCE_DIR}/cmake/module.rules.txt)
diff --git a/src/modules/popup/libkvipopup.cpp b/src/modules/popup/libkvipopup.cpp
new file mode 100644
index 000000000..4fc90025f
--- /dev/null
+++ b/src/modules/popup/libkvipopup.cpp
@@ -0,0 +1,200 @@
+//=============================================================================
+//
+// File : libkvipopup.cpp
+// Creation date : Fri Sep 03 2010 15:23:00 CEST by Fabio Bas
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2001-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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+//=============================================================================
+
+#include "kvi_module.h"
+#include "kvi_locale.h"
+#include "kvi_kvs_popupmanager.h"
+
+/*
+ @doc: popup.delitem
+ @type:
+ command
+ @title:
+ popup.delitem
+ @syntax:
+ popup.delitem [-d] [-q] <popupname:string> <item_id:string>
+ @short:
+ Deletes an item from a popup
+ @switches:
+ !sw: -q | --quiet
+ Run quietly
+ !sw: -d | --deep
+ Search the whole popup tree instead of only the first level
+ @description:
+ Deletes the item specified by <id> from the poup <popupname>.
+ If the -d flag is specified then the item with the specified
+ <id> is searched in the whole popup tree (containing submenus)
+ otherwise only the first level is searched. [br]
+ If the -q flag is specified, the command does not complain
+ about non-existent items or popup menus.[br]
+ See [cmd]defpopup[/cmd] for more information.[br]
+ @seealso:
+ [cmd]defpopup[/cmd], [cmd]popup[/cmd]
+*/
+
+
+static bool popup_kvs_cmd_delitem(KviKvsModuleCommandCall * c)
+{
+ QString szPopupName,szItemId;
+ KVSM_PARAMETERS_BEGIN(c)
+ KVSM_PARAMETER("popupname",KVS_PT_NONEMPTYSTRING,0,szPopupName)
+ KVSM_PARAMETER("item_id",KVS_PT_NONEMPTYSTRING,0,szItemId)
+ KVSM_PARAMETERS_END(c)
+
+ KviKvsPopupMenu * p = KviKvsPopupManager::instance()->lookup(szPopupName);
+ if(!p)
+ {
+ if(!c->hasSwitch('q',"quiet"))
+ c->warning(__tr2qs_ctx("Inexisting popup \"%Q\"","kvs"),&szPopupName);
+ return true;
+ }
+
+ if(p->isLocked())
+ {
+ c->error(__tr2qs_ctx("Popup menu self-modification is not allowed (the popup is probably open)","kvs"));
+ return false;
+ }
+
+ if(!p->removeItemByName(szItemId,c->hasSwitch('d',"deep")))
+ {
+ if(!c->hasSwitch('q',"quiet"))
+ c->warning(__tr2qs_ctx("The menu item with id \"%Q\" does not exist in popup \"%Q\"","kvs"),&szItemId,&szPopupName);
+ }
+
+ KviKvsPopupManager::instance()->emitRefresh(szPopupName);
+ return true;
+}
+
+ /*
+ @doc: popup
+ @type:
+ command
+ @title:
+ popup
+ @syntax:
+ popup [-p=<screen_coordinates:string>] <popup_name:string> [<parameter1:variant> [<parameter2:variant> [...]]]
+ @short:
+ Shows a popup menu
+ @switches:
+ !sw: -p=<screen_coordinates:string> | --point=<screen_coordinates:string>
+ @description:
+ Shows the popup menu <popup_name> at the current cursor position,
+ eventually passing the [parameters]. Please note that you can't
+ use this command inside one of the [cmd]defpopup[/cmd] command
+ handlers for <popup_name>. In other words, you can't "popup
+ a popup" while it is being popped up. :) (This would
+ be an endless recursive behaviour).[br]
+ If the -p switch is used, then <screen_coordinates> must be
+ in the form <x>,<y> and will be used as screen coordinates
+ for the placement of the popup (instead of the current cursor position).[br]
+ @seealso:
+ [cmd]defpopup[/cmd]
+ */
+
+static bool popup_kvs_cmd_show(KviKvsModuleCommandCall * c)
+{
+ QString szPopupName;
+ KVSM_PARAMETERS_BEGIN(c)
+ KVSM_PARAMETER("popup_name",KVS_PT_NONEMPTYSTRING,0,szPopupName)
+ KVSM_PARAMETERS_END(c)
+
+ // copy parameters
+ KviKvsVariantList * pPopupParams = new KviKvsVariantList();
+ c->params()->first();
+ while(KviKvsVariant * v = c->params()->next())pPopupParams->append(new KviKvsVariant(*v));
+
+ KviKvsPopupMenu * pMenu = KviKvsPopupManager::instance()->lookup(szPopupName);
+
+ if(!pMenu)
+ {
+ delete pPopupParams;
+ pPopupParams = 0;
+ c->error(__tr2qs_ctx("Popup %Q is not defined","kvs"),&szPopupName);
+ return false;
+ }
+
+ if(pMenu->isLocked())
+ {
+ delete pPopupParams;
+ pPopupParams = 0;
+ c->error(__tr2qs_ctx("A popup menu cannot be popped up twice","kvs"));
+ return false;
+ }
+
+ QPoint pnt = QCursor::pos();
+
+ KviKvsVariant * pCoords = c->getSwitch('p',"point");
+ if(pCoords)
+ {
+ QString szCoords;
+ pCoords->asString(szCoords);
+
+ int idx = szCoords.indexOf(',');
+ bool bCoordsOk = true;
+ if(idx == -1)bCoordsOk = false;
+ else {
+ QString szX = szCoords.left(idx);
+ szCoords.remove(0,idx + 1);
+ bool bOk1,bOk2;
+ int iX = szX.toInt(&bOk1);
+ int iY = szCoords.toInt(&bOk2);
+ if(bOk1 && bOk2)pnt = QPoint(iX,iY);
+ else bCoordsOk = false;
+ }
+
+ if(!bCoordsOk)c->warning(__tr2qs_ctx("Invalid syntax for screen coordinates, using cursor position","kvs"));
+ }
+
+ pMenu->doPopup(pnt,c->window(),pPopupParams);
+ return true;
+}
+
+static bool popup_module_init(KviModule *m)
+{
+ KVSM_REGISTER_SIMPLE_COMMAND(m,"delitem",popup_kvs_cmd_delitem);
+ KVSM_REGISTER_SIMPLE_COMMAND(m,"show",popup_kvs_cmd_show);
+ return true;
+}
+
+static bool popup_module_cleanup(KviModule *)
+{
+ return true;
+}
+
+static bool popup_module_can_unload(KviModule *)
+{
+ return true;
+}
+
+KVIRC_MODULE(
+ "Userlist", // module name
+ "4.0.0", // module version
+ "Copyright (C) 2010 Fabio Bas (ctrlaltca at gmail dot com)", // author & (C)
+ "KVIrc popup management functions",
+ popup_module_init,
+ popup_module_can_unload,
+ 0,
+ popup_module_cleanup,
+ 0
+)