File indexing completed on 2024-03-24 15:43:32

0001 /***************************************************************************
0002                           kmuddy.cpp  -  main class that handles interface
0003     This file is a part of KMuddy distribution.
0004                              -------------------
0005     begin                : Jun 14 12:37:51 CEST 2002
0006     copyright            : (C) 2002-2007 by Tomas Mecir
0007     email                : kmuddy@kmuddy.com
0008  ***************************************************************************/
0009 
0010 /***************************************************************************
0011  *                                                                         *
0012  *   This program is free software; you can redistribute it and/or modify  *
0013  *   it under the terms of the GNU General Public License as published by  *
0014  *   the Free Software Foundation; either version 2 of the License, or     *
0015  *   (at your option) any later version.                                   *
0016  *                                                                         *
0017  ***************************************************************************/
0018 
0019 #include <config-mxp.h>
0020 
0021 #include "kmuddy.h"
0022 
0023 #include "cactionmanager.h"
0024 #include "cbuttonlist.h"
0025 #include "ccmdparser.h"
0026 #include "cconnection.h"
0027 #include "cconsole.h"
0028 #include "cgaugebar.h"
0029 #include "cinputline.h"
0030 #include "clistmanager.h"
0031 #include "cmacromanager.h"
0032 #include "cmenumanager.h"
0033 #include "coutput.h"
0034 #include "cpluginmanager.h"
0035 #include "csession.h"
0036 #include "csessionmanager.h"
0037 #include "cshortcutlist.h"
0038 #include "csoundplayer.h"
0039 #include "ctabwidget.h"
0040 #include "ctranscript.h"
0041 #include "ctelnet.h"
0042 
0043 #include "cglobalsettings.h"
0044 #include "cmultilineinput.h"
0045 
0046 #ifdef HAVE_MXP
0047 #include "cmxpconsole.h"
0048 #endif
0049 
0050 #include "dialogs/dlgappsettings.h"
0051 #include "dialogs/dlgconnect.h"
0052 #include "dialogs/dlgquickconnect.h"
0053 #include "dialogs/dlgeditprofile.h"
0054 #include "dialogs/dlggrabkey.h"
0055 #include "dialogs/dlgimportexportprofile.h"
0056 #include "dialogs/dlgobjects.h"
0057 #include "dialogs/dlgstatistics.h"
0058 
0059 #include <stdlib.h>
0060 #include <ctime>
0061 
0062 #include <QAction>
0063 #include <QApplication>
0064 #include <QDesktopWidget>
0065 #include <QIcon>
0066 #include <QKeyEvent>
0067 #include <QMenu>
0068 #include <QMenuBar>
0069 #include <QTimer>
0070 
0071 #include <kaboutapplicationdialog.h>
0072 #include <kactioncollection.h>
0073 #include <kactionmenu.h>
0074 #include <khelpmenu.h>
0075 #include <KIconLoader>
0076 #include <KLocalizedString>
0077 #include <kmessagebox.h>
0078 #include <KNotification>
0079 #include <ktoggleaction.h>
0080 #include <ktoolbar.h>
0081 #include <KStatusNotifierItem>
0082 
0083 KMuddy *KMuddy::_self = nullptr;
0084 
0085 //are the actions ready?
0086 bool actionsReady;
0087 
0088 bool KMuddy::goingDown = false;
0089 
0090 KMuddy *KMuddy::self() {
0091   if (!_self)
0092     _self = new KMuddy;
0093   return _self;
0094 }
0095 
0096 KMuddy::KMuddy() : KMainWindow(nullptr), cActionBase ("kmuddy", 0), sysIcon(nullptr)
0097 {
0098   //initialize random number generator (needed by cMSP)
0099   srand (time (nullptr));
0100 
0101   central = nullptr;
0102   actionsReady = false;
0103   globalnotify = localnotify = alwaysnotify = false;
0104   cdlg = nullptr;
0105   qdlg = nullptr;
0106   mdlg = nullptr;
0107   statdlg = nullptr;
0108   objdlg = nullptr;
0109   grabdlg = nullptr;
0110 
0111   _self = this;
0112   prepareObjects ();
0113 }
0114 
0115 KMuddy::~KMuddy()
0116 {
0117   goingDown = true;
0118   killObjects ();
0119 }
0120 
0121 void KMuddy::eventNothingHandler (QString event, int session)
0122 {
0123   if (event == "notify-request")
0124     requestNotify (session);
0125 
0126   if (event == "global-settings-changed") {
0127     cGlobalSettings *gs = cGlobalSettings::self();
0128     setAllowGlobalNotify (gs->getBool ("global-notify"));
0129     setAllowLocalNotify (gs->getBool ("local-notify"));
0130     setAlwaysNotify (gs->getBool ("always-notify"));
0131     setSysTrayEnabled (gs->getBool ("systray-enabled"));
0132     setPassivePopup (gs->getBool ("passive-popup"));
0133     if (!systrayenabled && sysIcon) {
0134       // Remove the system tray icn
0135       delete sysIcon;
0136       sysIcon = nullptr;
0137     }
0138     else if (systrayenabled && !sysIcon){
0139       // Load the system tray icon
0140       sysIcon = new KStatusNotifierItem(this);
0141       sysIcon->setIconByName("kmuddy");
0142       sysIcon->setStatus(KStatusNotifierItem::Active);
0143     }
0144     setAutoConnect (gs->getString ("auto-connect"));
0145   }
0146   if (event == "disconnected") {
0147     // disconnected - hide some things if that session is active
0148     if (cActionManager::self()->activeSession() == session) {
0149       buttonbar->hide ();
0150       showGauges (false);
0151     }
0152   }
0153 }
0154 
0155 void KMuddy::eventIntHandler (QString event, int, int par, int)
0156 {
0157   if (event == "session-activated") {
0158     // session activated - adjust the button bar accordingly
0159     cButtonList *bl = dynamic_cast<cButtonList *>(cListManager::self()->getList (par, "buttons"));
0160     if (!bl) {
0161       // this session has no buttonlist - nothing to do
0162       buttonbar->hide();
0163       return;
0164     }
0165     // update the button bar
0166     bl->updateButtons ();
0167   }
0168 }
0169 
0170 void KMuddy::eventChunkHandler (QString event, int session, cTextChunk *)
0171 {
0172   if ((event == "displayed-line") || (event == "displayed-prompt"))
0173     if (alwaysnotify) requestNotify (session);
0174 }
0175 
0176 void KMuddy::eventStringHandler (QString event, int, QString &par1,
0177     const QString &par2)
0178 {
0179   if (event == "focus-change")
0180     focusChange (par1, par2);
0181 }
0182 
0183 // some externs ... these are in macros.cpp
0184 void registerInternalMacros ();
0185 void unregisterInternalMacros ();
0186 
0187 #define KEY_SHIFT Qt::ShiftModifier
0188 #define KEY_CTRL Qt::ControlModifier
0189 #define KEY_ALT Qt::AltModifier
0190 
0191 void KMuddy::prepareObjects ()
0192 {
0193   // set the main window pointer
0194   cActionManager::self()->setMainWindow (this);
0195 
0196   // plug-in manager
0197   cPluginManager::self();  // initialise the plugin manager
0198   registerInternalMacros ();
0199 
0200   // get action collection, creating it if needed
0201   // it must exist before the settings are loaded
0202   cActionManager::self()->createACol (this);
0203   KActionCollection *acol = cActionManager::self()->getACol ();
0204   // associate this window with the collection - needed for shortcuts to always work correctly
0205   acol->addAssociatedWidget (this);
0206 
0207   cGlobalSettings *globalsettings = cGlobalSettings::self();
0208 
0209   // initialise dock windows
0210   cMultiLineInput::self();
0211   statdlg = new dlgStatistics (this);
0212   statdlg->hide ();
0213   statdlg->setObjectName ("statistics");
0214   addDockWidget (Qt::RightDockWidgetArea, statdlg);
0215   statdlg->setFloating (true);
0216 #ifdef HAVE_MXP
0217   cMXPConsole::self();
0218 #endif
0219 
0220   // initialise sound objects
0221   new cSoundPlayer (true);   // wave player
0222   new cSoundPlayer (false);  // midi player
0223 
0224   // add application directory to icon search path
0225   KIconLoader::global()->addAppDir ("kmuddy");
0226 
0227   // action manager
0228   am = cActionManager::self();
0229   addEventHandler ("displayed-line", 100, PT_TEXTCHUNK);
0230   addEventHandler ("displayed-prompt", 100, PT_TEXTCHUNK);
0231   addEventHandler ("notify-request", 50, PT_NOTHING);
0232   addEventHandler ("global-settings-changed", 50, PT_NOTHING);
0233   addEventHandler ("focus-change", 50, PT_STRING);
0234   addEventHandler ("session-activated", 50, PT_INT);
0235   addEventHandler ("disconnected", 50, PT_NOTHING);
0236 
0237   // now we create the menubar
0238   cMenuManager::self()->setMenuBar (menuBar());
0239 
0240   //Connection
0241   QAction *stdconnect = new QAction (this);
0242   stdconnect->setText (i18n ("&Connect..."));
0243   stdconnect->setIcon (QIcon::fromTheme ("network-connect"));
0244   stdconnect->setShortcut (KEY_CTRL+Qt::Key_N);
0245   connect (stdconnect, &QAction::triggered, this, &KMuddy::showAndHandleConnectDialog);
0246   acol->addAction ("Connect", stdconnect);
0247 
0248   QAction *qconnect = new QAction (this);
0249   qconnect->setText (i18n ("&QuickConnect..."));
0250   qconnect->setIcon (QIcon::fromTheme ("network-connect"));
0251   qconnect->setShortcut (KEY_CTRL+Qt::Key_O);
0252   connect (qconnect, &QAction::triggered, this, &KMuddy::showAndHandleQuickConnectDialog);
0253   acol->addAction ("QuickConnect", qconnect);
0254   QAction *dodisconnect = new QAction (this);
0255   dodisconnect->setText (i18n ("&Disconnect"));
0256   dodisconnect->setIcon (QIcon::fromTheme ("network-disconnect"));
0257   dodisconnect->setShortcut (KEY_CTRL+Qt::Key_D);
0258   connect (dodisconnect, &QAction::triggered, this, &KMuddy::doDisconnect);
0259   acol->addAction ("Disconnect", dodisconnect);
0260   QAction *reconnect = new QAction (this);
0261   reconnect->setText (i18n ("&Reconnect"));
0262   reconnect->setShortcut (KEY_CTRL+Qt::Key_R);
0263   connect (reconnect, &QAction::triggered, this, &KMuddy::doReconnect);
0264   acol->addAction ("Reconnect", reconnect);
0265   QAction *closetab = new QAction (this);
0266   closetab->setText (i18n ("Close &tab"));
0267   closetab->setShortcut (KEY_CTRL+Qt::Key_W);
0268   connect (closetab, &QAction::triggered, this, &KMuddy::closeTab);
0269   acol->addAction ("CloseTab", closetab);
0270   closetab->setEnabled (false);
0271   reconnect->setEnabled (false);
0272 
0273   //Edit
0274   KActionMenu *pastemenu = new KActionMenu (this);
0275   pastemenu->setText (i18n ("Paste &As"));
0276   pastemenu->setIcon (QIcon::fromTheme ("edit-paste"));
0277   acol->addAction ("PasteMenu", pastemenu);
0278   //"Paste As" items
0279   QAction *pastecommand = new QAction (this);
0280   pastecommand->setText (i18n ("&Command"));
0281   connect (pastecommand, &QAction::triggered, this, &KMuddy::pasteCommand);
0282   acol->addAction ("PasteCommand", pastecommand);
0283   QAction *pasteinput = new QAction (this);
0284   pasteinput->setText (i18n ("&Input"));
0285   connect (pasteinput, &QAction::triggered, this, &KMuddy::pasteInput);
0286   acol->addAction ("PasteInput", pasteinput);
0287   pastemenu->addAction(pastecommand);
0288   pastemenu->addAction(pasteinput);
0289 
0290   QAction *clipcopy = new QAction (this);
0291   clipcopy->setText (i18n ("Copy &Selection"));
0292   clipcopy->setIcon (QIcon::fromTheme ("edit-copy"));
0293   clipcopy->setShortcut (KEY_CTRL+Qt::Key_C);
0294   connect (clipcopy, &QAction::triggered, this, &KMuddy::addSelectionToClipboard);
0295   acol->addAction ("ClipboardCopy", clipcopy);
0296   KToggleAction *parsing = new KToggleAction (this);
0297   parsing->setText (i18n ("Enable command &parsing"));
0298   parsing->setIcon (QIcon::fromTheme ("go-jump"));
0299   parsing->setShortcut (KEY_CTRL+KEY_SHIFT+Qt::Key_P);
0300   connect (parsing, &QAction::triggered, this, &KMuddy::setParsing);
0301   parsing->setChecked (true);  //enabled by default
0302   acol->addAction ("EnableParsing", parsing);
0303   QAction *cancelpending = new QAction (this);
0304   cancelpending->setText (i18n ("Ca&ncel pending commands"));
0305   cancelpending->setIcon (QIcon::fromTheme ("list-remove"));
0306   connect (cancelpending, &QAction::triggered, this, &KMuddy::clearCommandQueue);
0307   acol->addAction ("CancelPending", cancelpending);
0308 
0309   //View
0310   QAction *showmultiline = cMultiLineInput::self()->dialog()->toggleViewAction ();
0311   showmultiline->setIcon (QIcon::fromTheme ("format-justify-left"));
0312   showmultiline->setShortcut (KEY_CTRL+KEY_SHIFT+Qt::Key_M);
0313   acol->addAction ("ShowMultiLine", showmultiline);
0314   KToggleAction *showgaugebar = new KToggleAction (this);
0315   showgaugebar->setText (i18n ("Show &gaugebar"));
0316   connect (showgaugebar, &KToggleAction::toggled, this, &KMuddy::showGauges);
0317   showgaugebar->setChecked (false);
0318   acol->addAction ("ShowGaugeBar", showgaugebar);
0319   QAction *showstatistics = statdlg->toggleViewAction ();
0320   acol->addAction ("ShowStatistics", showstatistics);
0321 #ifdef HAVE_MXP
0322   QAction *showmxpconsole = cMXPConsole::self()->dialog()->toggleViewAction ();
0323   acol->addAction ("ShowMXPConsole", showmxpconsole);
0324 #endif
0325 
0326   //Profile
0327   QAction *objects = new QAction (this);
0328   objects->setText (i18n ("&Object Editor..."));
0329   objects->setShortcut (KEY_CTRL+KEY_ALT+Qt::Key_O);
0330   connect (objects, &QAction::triggered, this, &KMuddy::showObjectsDialog);
0331   acol->addAction ("Objects", objects);
0332   QAction *windows = new QAction (this);
0333   windows->setText (i18n ("&Output windows..."));
0334   connect (windows, &QAction::triggered, this, &KMuddy::handleWindowsDialog);
0335   acol->addAction ("OutputWindows", windows);
0336   KToggleAction *switchaliases = new KToggleAction (this);
0337   switchaliases->setText (i18n ("A&liases enabled"));
0338   switchaliases->setShortcut (KEY_CTRL+KEY_SHIFT+Qt::Key_A);
0339   connect (switchaliases, &QAction::triggered, this, &KMuddy::switchAliases);
0340   switchaliases->setChecked (true);
0341   acol->addAction ("EnableAliases", switchaliases);
0342   KToggleAction *switchtriggers = new KToggleAction (this);
0343   switchtriggers->setText (i18n ("Tri&ggers enabled"));
0344   switchtriggers->setShortcut (KEY_CTRL+KEY_SHIFT+Qt::Key_T);
0345   connect (switchtriggers, &QAction::triggered, this, &KMuddy::switchTriggers);
0346   switchtriggers->setChecked (true);
0347   acol->addAction ("EnableTriggers", switchtriggers);
0348   KToggleAction *switchtimers = new KToggleAction (this);
0349   switchtimers->setText (i18n ("Tim&ers enabled"));
0350   connect (switchtimers, &QAction::triggered, this, &KMuddy::switchTimers);
0351   switchtimers->setChecked (true);
0352   acol->addAction ("EnableTimers", switchtimers);
0353   KToggleAction *switchshortcuts = new KToggleAction (this);
0354   switchshortcuts->setText (i18n ("Macro &keys enabled"));
0355   connect (switchshortcuts, &QAction::triggered, this, &KMuddy::switchShortcuts);
0356   switchshortcuts->setChecked (true);
0357   acol->addAction ("EnableMacroKeys", switchshortcuts);
0358   QAction *connprefs = new QAction (this);
0359   connprefs->setText (i18n ("&MUD Preferences..."));
0360   connprefs->setIcon (QIcon::fromTheme ("user-identity"));
0361   connect (connprefs, &QAction::triggered, this, &KMuddy::showConnPrefsDialog);
0362   acol->addAction ("ConnPrefs", connprefs);
0363   QAction *save = new QAction (this);
0364   save->setText (i18n ("&Save Profile"));
0365   save->setShortcut (KEY_CTRL+Qt::Key_S);
0366   connect (save, &QAction::triggered, this, &KMuddy::saveProfile);
0367   acol->addAction ("SaveProfile", save);
0368 
0369   //Tools
0370   QAction *sesstranscript = new QAction (this);
0371   sesstranscript->setText (i18n ("&Session transcript..."));
0372   sesstranscript->setIcon (QIcon::fromTheme ("utilities-log-viewer"));
0373   connect (sesstranscript, &QAction::triggered, this, &KMuddy::configureTranscript);
0374   acol->addAction ("Transcript", sesstranscript);
0375   QAction *dumpbuffer = new QAction (this);
0376   dumpbuffer->setText (i18n ("Dump output &buffer..."));
0377   connect (dumpbuffer, &QAction::triggered, this, &KMuddy::dumpBuffer);
0378   acol->addAction ("DumpBuffer", dumpbuffer);
0379   QAction *decide = new QAction (this);
0380   decide->setText (i18n ("&Decision assistant"));
0381   connect (decide, &QAction::triggered, this, &KMuddy::makeDecision);
0382   acol->addAction ("Decision", decide);
0383 /*  QAction *importprofile = new QAction (this);
0384   importprofile->setText (i18n ("&Import profile..."));
0385   connect (importprofile, &QAction::triggered, this, &KMuddy::importProfile);
0386   acol->addAction ("ImportProf", importprofile);
0387   QAction *exportprofile = new QAction (this);
0388   exportprofile->setText (i18n ("&Export profile..."));
0389   connect (exportprofile, &QAction::triggered, this, &KMuddy::exportProfile);
0390   acol->addAction ("ExportProf", exportprofile); */
0391 
0392   //Settings
0393   QAction *appconfig = new QAction (this);
0394   appconfig->setText (i18n ("&Global settings..."));
0395   appconfig->setIcon (QIcon::fromTheme ("configure"));
0396   connect (appconfig, &QAction::triggered, this, &KMuddy::showSettingsDialog);
0397   acol->addAction ("Global settings", appconfig);
0398   QAction *pluginsconfig = new QAction (this);
0399   pluginsconfig->setText (i18n ("&Plugins..."));
0400   connect (pluginsconfig, &QAction::triggered, cPluginManager::self(), &cPluginManager::showPluginsDialog);
0401   acol->addAction ("Plugins", pluginsconfig);
0402   QAction *showmenubar = acol->addAction (KStandardAction::ShowMenubar, "ShowMenuBar", this, &KMuddy::toggleShowMenu);
0403   KToggleAction *fullscreenmode = new KToggleAction (this);
0404   fullscreenmode->setText (i18n ("F&ull screen mode"));
0405   fullscreenmode->setIcon (QIcon::fromTheme ("view-fullscreen"));
0406   fullscreenmode->setShortcut (KEY_CTRL+KEY_SHIFT+Qt::Key_F);
0407   connect (fullscreenmode, &KToggleAction::toggled, this, &KMuddy::setFullScreen);
0408   acol->addAction ("SetFullScreen", fullscreenmode);
0409 
0410   //Help
0411 
0412   //other actions
0413   QAction *lineup = new QAction (this);
0414   lineup->setText (i18n ("Shift line up"));
0415   lineup->setShortcut (KEY_SHIFT+Qt::Key_Up);
0416   connect (lineup, &QAction::triggered, this, &KMuddy::lineUp);
0417   acol->addAction ("LineUp", lineup);
0418   QAction *linedown = new QAction (this);
0419   linedown->setText (i18n ("Shift line down"));
0420   linedown->setShortcut (KEY_SHIFT+Qt::Key_Down);
0421   connect (linedown, &QAction::triggered, this, &KMuddy::lineDown);
0422   acol->addAction ("LineDown", linedown);
0423   QAction *pageup = new QAction (this);
0424   pageup->setText (i18n ("Shift page up"));
0425   pageup->setShortcut (KEY_SHIFT+Qt::Key_PageUp);
0426   connect (pageup, &QAction::triggered, this, &KMuddy::pageUp);
0427   acol->addAction ("PageUp", pageup);
0428   QAction *pagedown = new QAction (this);
0429   pagedown->setText (i18n ("Shift page down"));
0430   pagedown->setShortcut (KEY_SHIFT+Qt::Key_PageDown);
0431   connect (pagedown, &QAction::triggered, this, &KMuddy::pageDown);
0432   acol->addAction ("PageDown", pagedown);
0433   QAction *aconup = new QAction (this);
0434   aconup->setText (i18n ("Split-screen up"));
0435   aconup->setShortcut (KEY_CTRL+KEY_ALT+Qt::Key_Up);
0436   connect (aconup, &QAction::triggered, this, &KMuddy::aconUp);
0437   acol->addAction ("AconUp", aconup);
0438   QAction *acondown = new QAction (this);
0439   acondown->setText (i18n ("Split-screen down"));
0440   acondown->setShortcut (KEY_CTRL+KEY_ALT+Qt::Key_Down);
0441   connect (acondown, &QAction::triggered, this, &KMuddy::aconDown);
0442   acol->addAction ("AconDown", acondown);
0443   QAction *prevtab = new QAction (this);
0444   prevtab->setText (i18n ("Previous tab"));
0445   prevtab->setShortcut (KEY_ALT+Qt::Key_PageUp);
0446   connect (prevtab, &QAction::triggered, this, &KMuddy::prevTab);
0447   acol->addAction ("PreviousTab", prevtab);
0448   QAction *nexttab = new QAction (this);
0449   nexttab->setText (i18n ("Next tab"));
0450   nexttab->setShortcut (KEY_ALT+Qt::Key_PageDown);
0451   connect (nexttab, &QAction::triggered, this, &KMuddy::nextTab);
0452   acol->addAction ("NextTab", nexttab);
0453   QAction *tabnum[10];
0454   tabnum[0] = new QAction (this);
0455   tabnum[0]->setText (i18nc ("%1 - tab number", "Switch to tab %1", "1"));
0456   tabnum[0]->setShortcut (KEY_ALT+Qt::Key_1);
0457   connect (tabnum[0], &QAction::triggered, this, &KMuddy::switchTab1);
0458   acol->addAction ("SwitchTab1", tabnum[0]);
0459   tabnum[1] = new QAction (this);
0460   tabnum[1]->setText (i18nc ("%1 - tab number", "Switch to tab %1", "2"));
0461   tabnum[1]->setShortcut (KEY_ALT+Qt::Key_2);
0462   connect (tabnum[1], &QAction::triggered, this, &KMuddy::switchTab2);
0463   acol->addAction ("SwitchTab2", tabnum[1]);
0464   tabnum[2] = new QAction (this);
0465   tabnum[2]->setText (i18nc ("%1 - tab number", "Switch to tab %1", "3"));
0466   tabnum[2]->setShortcut (KEY_ALT+Qt::Key_3);
0467   connect (tabnum[2], &QAction::triggered, this, &KMuddy::switchTab3);
0468   acol->addAction ("SwitchTab3", tabnum[2]);
0469   tabnum[3] = new QAction (this);
0470   tabnum[3]->setText (i18nc ("%1 - tab number", "Switch to tab %1", "4"));
0471   tabnum[3]->setShortcut (KEY_ALT+Qt::Key_4);
0472   connect (tabnum[3], &QAction::triggered, this, &KMuddy::switchTab4);
0473   acol->addAction ("SwitchTab4", tabnum[3]);
0474   tabnum[4] = new QAction (this);
0475   tabnum[4]->setText (i18nc ("%1 - tab number", "Switch to tab %1", "5"));
0476   tabnum[4]->setShortcut (KEY_ALT+Qt::Key_5);
0477   connect (tabnum[4], &QAction::triggered, this, &KMuddy::switchTab5);
0478   acol->addAction ("SwitchTab5", tabnum[4]);
0479   tabnum[5] = new QAction (this);
0480   tabnum[5]->setText (i18nc ("%1 - tab number", "Switch to tab %1", "6"));
0481   tabnum[5]->setShortcut (KEY_ALT+Qt::Key_6);
0482   connect (tabnum[5], &QAction::triggered, this, &KMuddy::switchTab6);
0483   acol->addAction ("SwitchTab6", tabnum[5]);
0484   tabnum[6] = new QAction (this);
0485   tabnum[6]->setText (i18nc ("%1 - tab number", "Switch to tab %1", "7"));
0486   tabnum[6]->setShortcut (KEY_ALT+Qt::Key_7);
0487   connect (tabnum[6], &QAction::triggered, this, &KMuddy::switchTab7);
0488   acol->addAction ("SwitchTab7", tabnum[6]);
0489   tabnum[7] = new QAction (this);
0490   tabnum[7]->setText (i18nc ("%1 - tab number", "Switch to tab %1", "8"));
0491   tabnum[7]->setShortcut (KEY_ALT+Qt::Key_8);
0492   connect (tabnum[7], &QAction::triggered, this, &KMuddy::switchTab8);
0493   acol->addAction ("SwitchTab8", tabnum[7]);
0494   tabnum[8] = new QAction (this);
0495   tabnum[8]->setText (i18nc ("%1 - tab number", "Switch to tab %1", "9"));
0496   tabnum[8]->setShortcut (KEY_ALT+Qt::Key_9);
0497   connect (tabnum[8], &QAction::triggered, this, &KMuddy::switchTab9);
0498   acol->addAction ("SwitchTab9", tabnum[8]);
0499   tabnum[9] = new QAction (this);
0500   tabnum[9]->setText (i18nc ("%1 - tab number", "Switch to tab %1", "10"));
0501   tabnum[9]->setShortcut (KEY_ALT+Qt::Key_0);
0502   connect (tabnum[9], &QAction::triggered, this, &KMuddy::switchTab10);
0503   acol->addAction ("SwitchTab10", tabnum[9]);
0504 
0505   actionsReady = true;
0506 
0507   cMenuManager *menu = cMenuManager::self();
0508 
0509   //create all the menus
0510   connectionMenu = new QMenu (this);
0511   editMenu = new QMenu (this);
0512   viewMenu = new QMenu (this);
0513   profileMenu = new QMenu (this);
0514   toolsMenu = new QMenu (this);
0515   settingsMenu = new QMenu (this);
0516   helpMenu = new KHelpMenu (this, QString(), false);
0517   
0518   menu->addMenuPosition ("menu-base");
0519   menu->addMenuPosition ("menu-plugin");
0520   menu->addMenuPosition ("menu-settings");
0521   menu->addMenuPosition ("menu-help");
0522 
0523   menu->addMenu (connectionMenu, i18n ("&Connection"), "menu-base");
0524   menu->addMenu (editMenu, i18n ("&Edit"), "menu-base");
0525   menu->addMenu (viewMenu, i18n ("&View"), "menu-base");
0526   menu->addMenu (profileMenu, i18n ("&Profile"), "menu-base");
0527   menu->addMenu (toolsMenu, i18n ("&Tools"), "menu-base");
0528   menu->addMenu (settingsMenu, i18n ("&Settings"), "menu-settings");
0529   menu->addMenu (helpMenu->menu(), i18n ("&Help"), "menu-help");
0530 
0531   // create item slots and add entries to them
0532 
0533   //menu Connection
0534   menu->addItemPosition ("connection-slot1", connectionMenu);
0535   menu->addItemPosition ("connection-slot2", connectionMenu);
0536   menu->addItemPosition ("connection-quit", connectionMenu);
0537   
0538   menu->plug (stdconnect, "connection-slot1");
0539   menu->plug (qconnect, "connection-slot1");
0540   menu->plug (dodisconnect, "connection-slot1");
0541   menu->plug (reconnect, "connection-slot2");
0542   menu->plug (closetab, "connection-slot2");
0543   menu->plug (KStandardAction::quit(this, &KMuddy::close, nullptr), "connection-quit");
0544 
0545   //menu Edit
0546   menu->addItemPosition ("edit-slot1", editMenu);
0547   menu->addItemPosition ("edit-slot2", editMenu);
0548   menu->addItemPosition ("edit-slot3", editMenu);
0549   menu->plug (clipcopy, "edit-slot1");
0550   menu->plug (pastemenu, "edit-slot1");
0551   menu->plug (parsing, "edit-slot2");
0552   menu->plug (cancelpending, "edit-slot3");
0553   
0554   //menu View
0555   menu->addItemPosition ("view-global", viewMenu);
0556   menu->addItemPosition ("view-profile", viewMenu);
0557   
0558   menu->plug (showmultiline, "view-global");
0559   menu->plug (showstatistics, "view-global");
0560   menu->plug (showgaugebar, "view-profile");
0561 #ifdef HAVE_MXP
0562   menu->plug (showmxpconsole, "view-profile");
0563 #endif
0564 
0565   //menu Profile
0566   menu->addItemPosition ("profile-objects", profileMenu);
0567   menu->addItemPosition ("profile-prefs", profileMenu);
0568   menu->addItemPosition ("profile-switches", profileMenu);
0569   menu->addItemPosition ("profile-other", profileMenu);
0570 
0571   menu->plug (objects, "profile-objects");
0572   menu->plug (windows, "profile-objects");
0573   menu->plug (connprefs, "profile-prefs");
0574   menu->plug (switchaliases, "profile-switches");
0575   menu->plug (switchtriggers, "profile-switches");
0576   menu->plug (switchtimers, "profile-switches");
0577   menu->plug (switchshortcuts, "profile-switches");
0578   menu->plug (save, "profile-other");
0579 
0580   //menu Tools
0581   menu->addItemPosition ("tools-slot1", toolsMenu);
0582   menu->addItemPosition ("tools-slot2", toolsMenu);
0583   menu->addItemPosition ("tools-slot3", toolsMenu);
0584   
0585   menu->plug (sesstranscript, "tools-slot1");
0586   menu->plug (dumpbuffer, "tools-slot1");
0587   menu->plug (decide, "tools-slot2");
0588 //  menu->plug (importprofile, "tools-slot3");
0589 //  menu->plug (exportprofile, "tools-slot3");
0590 
0591   //menu Settings
0592   menu->addItemPosition ("settings-slot1", settingsMenu);
0593   menu->addItemPosition ("settings-slot2", settingsMenu);
0594   menu->addItemPosition ("settings-slot3", settingsMenu);
0595   
0596   menu->plug (showmenubar, "settings-slot1");
0597   menu->plug (fullscreenmode, "settings-slot2");
0598   menu->plug (appconfig, "settings-slot3");
0599   menu->plug (pluginsconfig, "settings-slot3");
0600 
0601   //menu Help
0602 
0603   // global actions are tied to the main window
0604   addAction (lineup);
0605   addAction (linedown);
0606   addAction (pageup);
0607   addAction (pagedown);
0608   addAction (aconup);
0609   addAction (acondown);
0610   addAction (prevtab);
0611   addAction (nexttab);
0612   for (int i = 0; i < 10; ++i) addAction (tabnum[i]);
0613 
0614   buttonbar = new KToolBar ("buttonbar", this, Qt::TopToolBarArea);
0615   buttonbar->setWindowTitle ("Button toolbar");
0616   buttonbar->hide ();
0617 
0618   central = new cTabWidget (this);
0619   central->setMinimumSize (400, 300);
0620   central->setTabShape (QTabWidget::Triangular);
0621   connect (central, &cTabWidget::currentChanged, this, &KMuddy::changeSession);
0622   cSessionManager::self()->setMainWidget (central);
0623 
0624   //prepare the new session
0625   cSessionManager::self()->addSession (false);
0626 
0627   //set up the window
0628   setCentralWidget (central);
0629 
0630   //read saved keys for acol object
0631   acol->setConfigGroup ("Shortcuts");
0632   acol->readSettings ();
0633 
0634   // load all the plug-ins
0635   cPluginManager::self()->loadAll ();
0636 
0637   //we're not connected on startup, so let's disable some options...
0638   disableConnectedOptions ();
0639   disableAdvancedOptions ();
0640 
0641   //apply global settings
0642   globalsettings->notifyChange ();
0643 
0644   //look if there's some auto-connect profile set
0645   if (!autoconnect.isEmpty())
0646     doProfileConnect (autoconnect, false);
0647 
0648   //let the window remember its position!
0649   setAutoSaveSettings ();
0650 
0651   //make sure that menu bar is visible each time kmuddy is started
0652   if (!menuBar()->isVisible())
0653     toggleShowMenu ();
0654   
0655 }
0656 
0657 void KMuddy::pasteCommand ()
0658 {
0659   //Should we allow it to addCommand even with no global clipboard input?
0660   //If we do, sends a newline (no big deal, may even be a 'feature')
0661   //All depends on how we want this set up; atm not allowing empty clipboard
0662 
0663   QClipboard *clipboard = QApplication::clipboard();
0664   if (clipboard->text().isNull())
0665     return;
0666 
0667   QString txt = clipboard->text(QClipboard::Clipboard);
0668   am->invokeEvent ("send-command", activeSession(), txt);
0669 }
0670 
0671 void KMuddy::pasteInput ()
0672 {
0673   cInputLine *inputline = dynamic_cast<cInputLine *>(am->object ("inputline", activeSession()));
0674   inputline->paste ();
0675 }
0676 
0677 void KMuddy::killObjects ()
0678 {
0679   //destroy objects and set pointers to 0 - needed so that we can prevent
0680   //some crashes if some object calls a function of an object that has already
0681   //been destroyed; this gives him a chance to verify its state...
0682 
0683   //menubar and KActions are not deleted...
0684 
0685   //session objects are NOT deleted here - doing so causes kmuddy to crash
0686 
0687   removeEventHandler ("displayed-line");
0688   removeEventHandler ("displayed-prompt");
0689   removeEventHandler ("notify-request");
0690   removeEventHandler ("global-settings-changed");
0691   removeEventHandler ("focus-change");
0692   removeEventHandler ("session-activated");
0693   removeEventHandler ("disconnected");
0694 
0695   delete cGlobalSettings::self();
0696 
0697   delete cPluginManager::self();
0698   unregisterInternalMacros ();
0699   delete cMacroManager::self();
0700 
0701   //also delete some dialogs...
0702   delete statdlg;
0703   delete objdlg;
0704   delete qdlg;
0705 
0706   delete sysIcon;
0707 }
0708 
0709 void KMuddy::saveProperties (KConfigGroup & /*config*/)
0710 {
0711   //nothing here for now, maybe I'll include re-connecting later?
0712 }
0713 
0714 void KMuddy::readProperties (const KConfigGroup & /*config*/)
0715 {
0716   //nothing here now now, maybe I'll include re-connecting later?
0717 }
0718 
0719 void KMuddy::disableConnectedOptions ()
0720 //may contain further commands...
0721 {
0722   if (!actionsReady) return;
0723   KActionCollection *acol = am->getACol ();
0724   QAction *dodisconnect = acol->action ("Disconnect");
0725   QAction *sesstranscript = acol->action ("Transcript");
0726   QAction *dumpbuffer = acol->action ("DumpBuffer");
0727 
0728   dodisconnect->setEnabled (false);
0729   sesstranscript->setEnabled (false);
0730   dumpbuffer->setEnabled (false);
0731 
0732   disableAdvancedOptions ();
0733 }
0734 
0735 void KMuddy::enableConnectedOptions ()
0736 //may contain further commands...
0737 {
0738   if (!actionsReady) return;
0739   KActionCollection *acol = am->getACol ();
0740   QAction *dodisconnect = acol->action ("Disconnect");
0741   QAction *reconnect = acol->action ("Reconnect");
0742   QAction *sesstranscript = acol->action ("Transcript");
0743   QAction *dumpbuffer = acol->action ("DumpBuffer");
0744   
0745   if (!(dodisconnect->isEnabled()))
0746     dodisconnect->setEnabled (true);
0747   if (!(sesstranscript->isEnabled()))
0748     sesstranscript->setEnabled (true);
0749   if (!(dumpbuffer->isEnabled()))
0750     dumpbuffer->setEnabled (true);
0751   reconnect->setEnabled (false);
0752 }
0753 
0754 void KMuddy::disableAdvancedOptions ()
0755 //may contain further commands...
0756 {
0757   if (!actionsReady) return;
0758   KActionCollection *acol = am->getACol ();
0759  
0760   acol->action ("ShowGaugeBar")->setEnabled (false);
0761   profileMenu->setEnabled (false);
0762 
0763   //!!! must also disable all profile-related actions!!! (otherwise
0764   //they're still accessible with hotkeys)
0765   acol->action("OutputWindows")->setEnabled (false);
0766   acol->action("EnableAliases")->setEnabled (false);
0767   acol->action("EnableTriggers")->setEnabled (false);
0768   acol->action("EnableTimers")->setEnabled (false);
0769   acol->action("EnableMacroKeys")->setEnabled (false);
0770   acol->action("ConnPrefs")->setEnabled (false);
0771 }
0772 
0773 void KMuddy::enableAdvancedOptions ()
0774 //may contain further commands...
0775 {
0776   if (!actionsReady) return;
0777   KActionCollection *acol = am->getACol ();
0778   
0779   acol->action ("ShowGaugeBar")->setEnabled (true);
0780   profileMenu->setEnabled (true);
0781 
0782   acol->action("OutputWindows")->setEnabled (true);
0783   acol->action("EnableAliases")->setEnabled (true);
0784   acol->action("EnableTriggers")->setEnabled (true);
0785   acol->action("EnableTimers")->setEnabled (true);
0786   acol->action("EnableMacroKeys")->setEnabled (true);
0787   acol->action("ConnPrefs")->setEnabled (true);
0788 }
0789 
0790 void KMuddy::setClosedConn (bool canCT)
0791 {
0792   if (!actionsReady) return;
0793   
0794   KActionCollection *acol = am->getACol ();
0795   acol->action ("CloseTab")->setEnabled (canCT);
0796   acol->action ("Reconnect")->setEnabled (true);
0797 }
0798 
0799 void KMuddy::unsetClosedConn ()
0800 {
0801   if (!actionsReady) return;
0802   
0803   KActionCollection *acol = am->getACol ();
0804   acol->action ("CloseTab")->setEnabled (false);
0805   acol->action ("Reconnect")->setEnabled (false);
0806 }
0807 
0808 void KMuddy::closeTab ()
0809 {
0810   //close that session...
0811   cConnection *conn = dynamic_cast<cConnection *>(am->object ("connection", activeSession()));
0812 
0813   if (conn->isConnected ())
0814     doDisconnect();
0815   if (!conn->isConnected())
0816     cSessionManager::self()->removeSession (activeSession(), false);
0817 }
0818 
0819 void KMuddy::setFullScreen (bool val)
0820 {
0821   KActionCollection *acol = am->getACol ();
0822   QAction *showmenubar = acol->action ("ShowMenuBar");
0823   if (val) {
0824     showFullScreen();
0825     if (menuBar()->isVisible())
0826       toggleShowMenu();
0827     showmenubar->setChecked( ! menuBar()->isHidden() );
0828   }
0829   else
0830     if (isFullScreen()) {
0831       showNormal();
0832       if (!menuBar()->isVisible())
0833         toggleShowMenu();
0834       showmenubar->setChecked( ! menuBar()->isHidden() );
0835     }
0836 }
0837 
0838 void KMuddy::toggleShowMenu()
0839 {
0840   if (menuBar()->isVisible())
0841     menuBar()->hide();
0842   else
0843     menuBar()->show();
0844 }
0845 
0846 void KMuddy::showGauges (bool val)
0847 {
0848   cGaugeBar *gauges = dynamic_cast<cGaugeBar *>(am->object ("gaugebar", activeSession()));
0849 
0850   bool shown = gauges->isVisible ();
0851   if (val)
0852     gauges->show ();
0853   else
0854     gauges->hide ();
0855 
0856   //keep action in sync (this function can be explicitly called)
0857   KActionCollection *acol = am->getACol ();
0858   acol->action ("ShowGaugeBar")->setChecked (val);
0859 
0860   if (val != shown) {
0861     //showing/hiding toolbar shifts view - fix it!
0862     //!!! THIS IS FAR FROM BEING IDEAL !!!
0863     list<int>::iterator it;
0864     list<int> sess = am->sessionList ();
0865     for (it = sess.begin(); it != sess.end(); ++it) {
0866       cConsole *console = (dynamic_cast<cOutput *>(am->object("output", *it)))->console();
0867       console->pageDown ();
0868     }
0869   }
0870 }
0871 
0872 // TODO: this should get moved to session manager and command processor
0873 // session manager would return session ID with a given prefix, command
0874 // processor would send command ...
0875 void KMuddy::focusChange (const QString &window, const QString &command)
0876 {
0877   QString sessName;
0878   int id = -1;
0879 
0880   list<int>::iterator it;
0881   list<int> sess = am->sessionList ();
0882   for (it = sess.begin(); it != sess.end(); ++it) {
0883     sessName = am->callAction ("session", "name", *it);
0884     if (sessName.startsWith(window)) {
0885       id = *it;
0886       //breaking here means that if more than one session matching
0887       //window name is found, that sessionName will use the first
0888       //ie - sessions: 'abc' and 'abc123' - whichever has the lowest
0889       //sessionid will be the session the command is sent to if only
0890       //'abc' is passed as the WINDOW
0891       break;
0892     }
0893   }
0894   if (id <= 0)
0895     return; //return without sending command
0896 
0897   // send the command to the necessary session - it will be sent as-is
0898   am->invokeEvent ("send-command", id, command);
0899 }
0900 
0901 QString KMuddy::reconnectText ()
0902 {
0903   KActionCollection *acol = am->getACol ();
0904   QAction *reconnect = acol->action ("Reconnect");
0905   return i18n ("To reconnect, press %1 or use Connection / Reconnect.", reconnect->shortcut().toString());;
0906 }
0907 
0908 void KMuddy::updateWindows ()
0909 {
0910   // TODO: the windows could react on events and update themselves ...
0911   // then we won't need this at all ...
0912 
0913   // update the statistics window
0914   if (statdlg != nullptr)
0915     statdlg->update ();
0916 }
0917 
0918 void KMuddy::changeSession (int tab)
0919 {
0920   int sess = cSessionManager::self()->getSessionByTab (tab);
0921   cSessionManager::self()->changeSession (sess);
0922 }
0923 
0924 int KMuddy::activeSession ()
0925 {
0926   return am->activeSession();
0927 }
0928 
0929 void KMuddy::setAutoConnect (const QString &ac)
0930 {
0931   autoconnect = ac;
0932 }
0933 
0934 void KMuddy::prevTab ()
0935 {
0936   int idx = central->currentIndex ();
0937   idx--;
0938   if (idx < 0)
0939     idx = central->count() - 1;
0940   central->setCurrentIndex (idx);
0941 }
0942 
0943 void KMuddy::nextTab ()
0944 {
0945   int idx = central->currentIndex ();
0946   idx++;
0947   if (idx >= central->count())
0948     idx = 0;
0949   central->setCurrentIndex (idx);
0950 }
0951 
0952 void KMuddy::switchTab (int index)
0953 {
0954   central->setCurrentIndex (index);
0955 }
0956 
0957 void KMuddy::setAllowGlobalNotify (bool notify)
0958 {
0959   globalnotify = notify;
0960 }
0961 
0962 
0963 void KMuddy::setAllowLocalNotify (bool notify)
0964 {
0965   localnotify = notify;
0966 }
0967 
0968 void KMuddy::setAlwaysNotify (bool notify)
0969 {
0970   alwaysnotify = notify;
0971 }
0972 
0973 void KMuddy::setSysTrayEnabled (bool enabled)
0974 {
0975   systrayenabled = enabled;
0976 }
0977 
0978 void KMuddy::setPassivePopup (bool enabled)
0979 {
0980   passivepopup = enabled;
0981 }
0982 
0983 void KMuddy::requestNotify (int sess)
0984 {
0985   //global notify
0986   if (globalnotify && (!isActiveWindow ())){
0987     // ask the window manager to draw attention to the window
0988     QApplication::alert(this);
0989     if (systrayenabled && sysIcon && passivepopup){
0990       KNotification *notification = new KNotification("Activity");
0991       notification->setText(i18n("Activity in the KMuddy Window"));
0992       QPixmap px;
0993       px.load("kmuddy.png");
0994       notification->setPixmap(px);
0995       connect(notification, QOverload<unsigned int>::of(&KNotification::activated), this, [sess]() { cSessionManager::self()->changeSession (sess); });
0996       notification->sendEvent();
0997     }
0998   }
0999 
1000   //local notify
1001   if (localnotify && (activeSession() != sess))
1002     cSessionManager::self()->setNotifyFlag (sess);
1003 }
1004 
1005 void KMuddy::setMenuAliasesEnabled (bool val)
1006 {
1007   KActionCollection *acol = am->getACol ();
1008   acol->action ("EnableAliases")->setChecked (val);
1009 }
1010 
1011 void KMuddy::setMenuTriggersEnabled (bool val)
1012 {
1013   KActionCollection *acol = am->getACol ();
1014   acol->action ("EnableTriggers")->setChecked (val);
1015 }
1016 
1017 void KMuddy::setMenuTimersEnabled (bool val)
1018 {
1019   KActionCollection *acol = am->getACol ();
1020   acol->action ("EnableTimers")->setChecked (val);
1021 }
1022 
1023 void KMuddy::setMenuShortcutsEnabled (bool val)
1024 {
1025   KActionCollection *acol = am->getACol ();
1026   acol->action ("EnableMacroKeys")->setChecked (val);
1027 }
1028 
1029 void KMuddy::doDisconnect ()
1030 {
1031   cConnection *connection;
1032   connection = dynamic_cast<cConnection *>(am->object ("connection", activeSession()));
1033   connection->handleDisconnect ();
1034 }
1035 
1036 void KMuddy::doReconnect ()
1037 {
1038   cConnection *connection;
1039   connection = dynamic_cast<cConnection *>(am->object ("connection", activeSession()));
1040   connection->reconnect ();
1041 
1042   // update alias/trigger groups and similar things ...
1043   updateWindows ();
1044 }
1045 
1046 //THESE METHODS WERE ORIGINALLY IN cConnection; now they're here because
1047 //of multi-tab support
1048 
1049 void KMuddy::doQuickConnect ()
1050 {
1051   //hide the dialog so that it doesn't look like we've crashed
1052   qdlg->hide ();
1053 
1054   //create a new session object and related stuff
1055   int s = cSessionManager::self()->addSession (false);
1056   cConnection *connection = dynamic_cast<cConnection *>(am->object ("connection", s));
1057   //now establish that connection!
1058   connection->establishQuickConnection (qdlg->host(), qdlg->port());
1059 
1060   updateWindows ();
1061 }
1062 
1063 void KMuddy::doConnect ()
1064 {
1065   //hide the dialog, so that it doesn't look like we've crashed
1066   cdlg->hide ();
1067 
1068   QString name = cdlg->selectedProfile ();
1069   bool sendNothing = cdlg->sendNothing ();
1070 
1071   doProfileConnect (name, sendNothing);
1072 }
1073 
1074 void KMuddy::doProfileConnect (const QString &name, bool sendNothing)
1075 {
1076   //create cSession object and related stuff
1077   int s = cSessionManager::self()->addSession (true);
1078 
1079   // offline connection
1080   if (cdlg && cdlg->isOffLine()) {
1081     cTelnet *telnet = dynamic_cast<cTelnet *>(am->object ("telnet", s));
1082     telnet->setOffLineConnection(true);
1083   }
1084 
1085   //now establish that connection!
1086   cConnection *connection = dynamic_cast<cConnection *>(am->object ("connection", s));
1087   connection->establishConnection (name, sendNothing);
1088 
1089   updateWindows ();
1090 }
1091 
1092 void KMuddy::showAndHandleConnectDialog ()
1093 {
1094   //so first we have to create the dialog...
1095   cdlg = new dlgConnect (this);
1096   connect (cdlg, &dlgConnect::accepted, this, &KMuddy::doConnect);
1097 
1098   //dialog is ready - show it!
1099   cdlg->exec ();
1100 
1101   //further action is handled by signal issued by OK button, so that we only
1102   //have to destroy the dialog...
1103   delete cdlg;
1104   cdlg = nullptr;
1105 }
1106 
1107 void KMuddy::showAndHandleQuickConnectDialog ()
1108 {
1109   //so first we have to create the dialog...
1110   if (!qdlg) qdlg = new dlgQuickConnect (this);
1111   connect (qdlg, &dlgQuickConnect::accepted, this, &KMuddy::doQuickConnect);
1112 
1113   //dialog is ready - show it!
1114   qdlg->exec ();
1115 
1116   //further action is handled by signal issued by OK button
1117 }
1118 
1119 /** lots of slots that handle menus; were handled by slots in objects,
1120 now we have cSession, so we have to handle it here */
1121 void KMuddy::addSelectionToClipboard ()
1122 {
1123   cOutput *output = dynamic_cast<cOutput *>(am->object ("output", activeSession()));
1124   output->console()->addSelectionToClipboard(QClipboard::Clipboard);
1125 }
1126 
1127 void KMuddy::setParsing (bool value)
1128 {
1129   list<int>::iterator it;
1130   list<int> sess = am->sessionList ();
1131   for (it = sess.begin(); it != sess.end(); ++it) {
1132     cCmdParser *cmdparser = dynamic_cast<cCmdParser *>(am->object ("cmdparser", *it));
1133     cmdparser->setParsing (value);
1134   }
1135 }
1136 
1137 void KMuddy::clearCommandQueue ()
1138 {
1139   // NOTHING HERE
1140   // TODO: make it work when command queues get implemented
1141   am->invokeEvent ("message", activeSession(), "Feature not implemented yet.");
1142 }
1143 
1144 void KMuddy::showObjectsDialog ()
1145 {
1146   if (!objdlg)
1147     objdlg = new dlgObjects (this);
1148   objdlg->show ();
1149 }
1150 
1151 void KMuddy::handleWindowsDialog ()
1152 {
1153   cConnection *connection;
1154   connection = dynamic_cast<cConnection *>(am->object ("connection", activeSession()));
1155   connection->handleWindowsDialog();
1156 }
1157 
1158 void KMuddy::saveProfile ()
1159 {
1160   cConnection *connection;
1161   connection = dynamic_cast<cConnection *>(am->object ("connection", activeSession()));
1162   connection->saveSession();
1163   am->invokeEvent ("message", activeSession(), i18n ("Profile has been saved. Note that profiles are automatically saved upon disconnecting, and also every five minutes."));
1164 }
1165 
1166 void KMuddy::switchAliases (bool value)
1167 {
1168   cConnection *connection;
1169   connection = dynamic_cast<cConnection *>(am->object ("connection", activeSession()));
1170   connection->switchAliases(value);
1171 }
1172 
1173 void KMuddy::switchTriggers (bool value)
1174 {
1175   cConnection *connection;
1176   connection = dynamic_cast<cConnection *>(am->object ("connection", activeSession()));
1177   connection->switchTriggers(value);
1178 }
1179 
1180 void KMuddy::switchTimers (bool value)
1181 {
1182   cConnection *connection;
1183   connection = dynamic_cast<cConnection *>(am->object ("connection", activeSession()));
1184   connection->switchTimers(value);
1185 }
1186 
1187 void KMuddy::switchShortcuts (bool value)
1188 {
1189   cConnection *connection;
1190   connection = dynamic_cast<cConnection *>(am->object ("connection", activeSession()));
1191   connection->switchShortcuts(value);
1192 }
1193 
1194 void KMuddy::showSettingsDialog ()
1195 {
1196   //so first we have to create the dialog...
1197   dlgAppSettings *sdlg = new dlgAppSettings (this);
1198 
1199   //next we fill in its data
1200   sdlg->putSettingsToDialog ();
1201 
1202   //dialog is ready - show it!
1203   sdlg->exec ();
1204 
1205   //further action is handled via slots issued by buttons, so that we only
1206   //have to destroy the dialog...
1207   delete sdlg;
1208 }
1209 
1210 void KMuddy::showConnPrefsDialog ()
1211 {
1212   cConnection *connection;
1213   connection = dynamic_cast<cConnection *>(am->object ("connection", activeSession()));
1214   connection->showConnPrefsDialog();
1215 }
1216 
1217 void KMuddy::configureTranscript ()
1218 {
1219   cTranscript *transcript;
1220   transcript = dynamic_cast<cTranscript *>(am->object ("transcript", activeSession()));
1221   transcript->configure();
1222 }
1223 
1224 void KMuddy::dumpBuffer ()
1225 {
1226   cTranscript *transcript;
1227   transcript = dynamic_cast<cTranscript *>(am->object ("transcript", activeSession()));
1228   transcript->dumpBuffer();
1229 }
1230 
1231 void KMuddy::makeDecision ()
1232 {
1233   cOutput *output = dynamic_cast<cOutput *>(am->object ("output", activeSession()));
1234   output->makeDecision();
1235 }
1236 
1237 void KMuddy::importProfile ()
1238 {
1239   dlgImportExportProfile *iep = new dlgImportExportProfile (true, this);
1240   iep->doThings ();
1241   delete iep;
1242 }
1243 
1244 void KMuddy::exportProfile ()
1245 {
1246   dlgImportExportProfile *iep = new dlgImportExportProfile (false, this);
1247   iep->doThings ();
1248   delete iep;
1249 }
1250 
1251 void KMuddy::lineUp ()
1252 {
1253   cOutput *output = dynamic_cast<cOutput *>(am->object ("output", activeSession()));
1254   output->console()->lineUp();
1255 }
1256 
1257 void KMuddy::lineDown ()
1258 {
1259   cOutput *output = dynamic_cast<cOutput *>(am->object ("output", activeSession()));
1260   output->console()->lineDown();
1261 }
1262 
1263 void KMuddy::pageUp ()
1264 {
1265   cOutput *output = dynamic_cast<cOutput *>(am->object ("output", activeSession()));
1266   output->console()->pageUp();
1267 }
1268 
1269 void KMuddy::pageDown ()
1270 {
1271   cOutput *output = dynamic_cast<cOutput *>(am->object ("output", activeSession()));
1272   output->console()->pageDown();
1273 }
1274 
1275 void KMuddy::aconUp ()
1276 {
1277   cOutput *output = dynamic_cast<cOutput *>(am->object ("output", activeSession()));
1278   output->aconUp();
1279 }
1280 
1281 void KMuddy::aconDown ()
1282 {
1283   cOutput *output = dynamic_cast<cOutput *>(am->object ("output", activeSession()));
1284   output->aconDown();
1285 }
1286 
1287 bool KMuddy::eventFilter (QObject *o, QEvent *e)
1288 {
1289   //only handle keypresses, nothing else...
1290   if (e->type() != QEvent::KeyPress)
1291     return KMainWindow::eventFilter (o, e);
1292 
1293   bool report = true;
1294   QKeyEvent *qke = (QKeyEvent *) e;
1295   int key = qke->key ();
1296   Qt::KeyboardModifiers mods = qke->modifiers ();
1297 
1298   //do not report modifiers
1299   switch (key) {
1300     case Qt::Key_Shift:
1301     case Qt::Key_Control:
1302     case Qt::Key_Meta:
1303     case Qt::Key_Alt:
1304       report = false;
1305       break;
1306     default:
1307       report = true;
1308       break;
1309   };
1310 
1311   if (report)
1312   {
1313     if (grabdlg)
1314     {
1315       grabdlg->gotKey (key, mods);
1316       return true;
1317     }
1318     else
1319     {
1320       cShortcutList *sl;
1321       sl = (cShortcutList *) cListManager::self()->getList (activeSession(), "macrokeys");
1322       if (sl && sl->handleKey (key, mods))
1323         return true;
1324     }
1325   }
1326   return KMainWindow::eventFilter (o, e);
1327 }
1328 
1329 bool KMuddy::queryClose ()
1330 {
1331   list<int>::iterator it;
1332   list<int> sess = am->sessionList ();
1333   for (it = sess.begin(); it != sess.end(); ++it) {
1334     //switch to that session => the user knows which one is about to close
1335     cSessionManager::self()->setSession (*it);
1336     //disconnect, asking the user whether he really wants to
1337     cConnection *connection = dynamic_cast<cConnection *>(am->object ("connection", *it));
1338     if (!connection->handleDisconnect())
1339       return false;
1340   }
1341 
1342   return true;
1343 }
1344 
1345 #include "moc_kmuddy.cpp"