File indexing completed on 2024-12-01 06:51:47

0001 /***************************************************************************
0002                           dlgrunninglist.cpp  -  Running Scripts dialog
0003                              -------------------
0004     begin                : So jan 18 2003
0005     copyright            : (C) 2003-2009 by Tomas Mecir
0006     email                : kmuddy@kmuddy.com
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 
0018 #include "dlgrunninglist.h"
0019 
0020 #include "crunninglist.h"
0021 
0022 #include <QLabel>
0023 #include <QTreeView>
0024 #include <QVBoxLayout>
0025 
0026 #include <kaction.h>
0027 #include <KLocalizedString>
0028 
0029 dlgRunningList::dlgRunningList (QWidget *parent) : QDockWidget (parent)
0030 {
0031   setWindowTitle (i18n ("Running scripts"));
0032     
0033   //main widget
0034   QWidget *page = new QWidget (this);
0035   QVBoxLayout *layout = new QVBoxLayout (page);
0036 
0037   setWidget (page);
0038 
0039   QLabel *label = new QLabel (i18n ("&Running scripts"), page);
0040   view = new QTreeView (page);
0041   view->setModel (0);
0042   view->setAllColumnsShowFocus (true);
0043   view->setRootIsDecorated (false);
0044   view->setUniformRowHeights (true);
0045   view->setContextMenuPolicy (Qt::ActionsContextMenu);
0046   label->setBuddy (view);
0047 
0048   // actions
0049   KAction *actTerminate = new KAction (view);
0050   actTerminate->setText (i18n ("&Terminate"));
0051   connect (actTerminate, SIGNAL (triggered()), this, SLOT (terminateScript()));
0052   view->addAction (actTerminate);
0053   KAction *actKill = new KAction (view);
0054   actKill->setText (i18n ("&Kill"));
0055   connect (actKill, SIGNAL (triggered()), this, SLOT (killScript()));
0056   view->addAction (actKill);
0057 
0058   layout->setSpacing (5);
0059   layout->addWidget (label);
0060   layout->addWidget (view);
0061 }
0062 
0063 dlgRunningList::~dlgRunningList()
0064 {
0065   //nothing here
0066 }
0067 
0068 void dlgRunningList::switchRunningList (cRunningList *newlist)
0069 {
0070   rlist = newlist;
0071   view->setModel (rlist ? rlist->getModel() : 0);
0072 }
0073 
0074 void dlgRunningList::terminateScript ()
0075 {
0076   int id = selectedId ();
0077   if (id < 0) return;
0078   rlist->terminate (id);
0079 }
0080 
0081 void dlgRunningList::killScript ()
0082 {
0083   int id = selectedId ();
0084   if (id < 0) return;
0085   rlist->kill (id);
0086 }
0087 
0088 int dlgRunningList::selectedId ()
0089 {
0090   if (!rlist) return -1; //if there is no runninglist, there's nothing to do
0091 
0092   QModelIndex idx = view->currentIndex ();
0093   if (!idx.isValid()) return -1;  // something must be selected
0094 
0095   return rlist->getModel()->data (idx, Qt::UserRole).toInt();
0096 }
0097 
0098 #include "moc_dlgrunninglist.cpp"