From 3e328b47c6bc8e2629666d6d2f6fb68bf2a823b5 Mon Sep 17 00:00:00 2001 From: Alf Gaida Date: Sun, 27 Dec 2015 03:37:27 +0100 Subject: [PATCH] Cherry-picking upstream version 1.10.16+20151210. Removed dbg package in favor of dbgsym. Removed unused files and licenses from copyright. Installed manpage. --- CMakeLists.txt | 9 +- debian/changelog | 9 + debian/control | 12 - debian/copyright | 47 -- debian/manpages | 1 + debian/rules | 9 +- icon/preferences-system.png | Bin 2868 -> 0 bytes src/qps.qrc => qps.qrc | 1 - src/CMakeLists.txt | 27 +- src/checkboxdelegate.cpp | 94 ++++ src/checkboxdelegate.h | 30 ++ src/command.cpp | 920 +----------------------------------- src/command.h | 187 +------- src/commanddialog.cpp | 257 ++++++++++ src/commanddialog.h | 47 ++ src/commandmodel.cpp | 47 ++ src/commandmodel.h | 21 + src/commandutils.cpp | 76 +++ src/commandutils.h | 17 + src/details.h | 10 +- src/execwindow.cpp | 112 +++++ src/execwindow.h | 37 ++ src/listmodel.cpp | 107 +++++ src/listmodel.h | 36 ++ src/misc.cpp | 2 - src/misc.h | 2 - src/qps.cpp | 96 +--- src/qps.h | 3 + src/qpsapp.cpp | 61 +++ src/qpsapp.h | 29 ++ src/qticonloader.cpp | 389 --------------- src/qticonloader.h | 55 --- src/tablefield.h | 18 + src/watchcond.cpp | 76 +++ src/watchcond.h | 50 ++ src/watchdogdialog.cpp | 239 ++++++++++ src/watchdogdialog.h | 48 ++ 37 files changed, 1463 insertions(+), 1718 deletions(-) create mode 100644 debian/manpages delete mode 100644 icon/preferences-system.png rename src/qps.qrc => qps.qrc (84%) create mode 100644 src/checkboxdelegate.cpp create mode 100644 src/checkboxdelegate.h create mode 100644 src/commanddialog.cpp create mode 100644 src/commanddialog.h create mode 100644 src/commandmodel.cpp create mode 100644 src/commandmodel.h create mode 100644 src/commandutils.cpp create mode 100644 src/commandutils.h create mode 100644 src/execwindow.cpp create mode 100644 src/execwindow.h create mode 100644 src/listmodel.cpp create mode 100644 src/listmodel.h create mode 100644 src/qpsapp.cpp create mode 100644 src/qpsapp.h delete mode 100644 src/qticonloader.cpp delete mode 100644 src/qticonloader.h create mode 100644 src/tablefield.h create mode 100644 src/watchcond.cpp create mode 100644 src/watchcond.h create mode 100644 src/watchdogdialog.cpp create mode 100644 src/watchdogdialog.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a1c6641..d8e22e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR) -set(PROJECT qps) -project(${PROJECT}) +project(qps) option(UPDATE_TRANSLATIONS "Update source translation translations/*.ts files" OFF) @@ -60,9 +59,9 @@ install(FILES # building tarball with CPack include(InstallRequiredSystemLibraries) -set(CPACK_PACKAGE_VERSION_MAJOR ${LXQT_MAJOR_VERSION}) -set(CPACK_PACKAGE_VERSION_MINOR ${LXQT_MINOR_VERSION}) -set(CPACK_PACKAGE_VERSION_PATCH ${LXQT_PATCH_VERSION}) +set(CPACK_PACKAGE_VERSION_MAJOR ${MAJOR_VERSION}) +set(CPACK_PACKAGE_VERSION_MINOR ${MINOR_VERSION}) +set(CPACK_PACKAGE_VERSION_PATCH ${PATCH_VERSION}) set(CPACK_GENERATOR TBZ2) set(CPACK_SOURCE_GENERATOR TBZ2) set(CPACK_SOURCE_IGNORE_FILES /build/;.gitignore;.*~;.git;.kdev4;temp) diff --git a/debian/changelog b/debian/changelog index be01ef4..6b5237e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +qps (1.10.16+20151210-1) unstable; urgency=medium + + * Cherry-picking upstream version 1.10.16+20151210. + * Removed dbg package in favor of dbgsym. + * Removed unused files and licenses from copyright. + * Installed manpage. + + -- Alf Gaida Sun, 27 Dec 2015 03:37:11 +0100 + qps (1.10.16+20150823-1) unstable; urgency=medium * Initial Release (Closes: #795697) diff --git a/debian/control b/debian/control index a36f7d1..cfca35b 100644 --- a/debian/control +++ b/debian/control @@ -22,15 +22,3 @@ Depends: ${shlibs:Depends}, ${misc:Depends} Description: Qt process manager Qt process manager ported to Qt5 - -Package: qps-dbg -Architecture: any -Section: debug -Priority: extra -Depends: ${shlibs:Depends}, - ${misc:Depends}, - qps (= ${binary:Version}) -Description: Qt process manager (debug) - Qt process manager ported to Qt5 - . - This package contains debugging symbols for qps. diff --git a/debian/copyright b/debian/copyright index 4dc4c05..972cc38 100644 --- a/debian/copyright +++ b/debian/copyright @@ -26,10 +26,6 @@ Copyright: 1997-1999 Mattias EngdegÃ¥rd 2015- daehyun.yang@gmail.com License: GPL-2.0+ -Files: src/qticonloader.* -Copyright: Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -License: LGPL-2.1-Nokia-Qt-Exception-1 or GPL-3 - Files: src/qttableview.* Copyright: 1992-2000 Trolltech AS License: GPL-2.0 or QPL-1.0 @@ -121,49 +117,6 @@ License: LGPL-2.1+ On Debian systems, the complete text of the GNU Lesser General Public License can be found in "/usr/share/common-licenses/LGPL-2.1". -License: LGPL-2.1-Nokia-Qt-Exception-1 - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; - version 2.1 of the License. - . - This library 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 - Lesser General Public License for more details. - . - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - . - On Debian systems, the full text of the GNU Lesser General Public - License version 2.1 can be found in the file - `/usr/share/common-licenses/LGPL-2.1'. - . - Nokia Qt LGPL Exception version 1.0 - . - As a special exception to the GNU Lesser General Public License - version 2.1, the object code form of a "work that uses the Library" - may incorporate material from a header file that is part of the - Library. You may distribute such object code under terms of your - choice, provided that the incorporated material (i) does not exceed - more than 5% of the total size of the Library; and (ii) is limited to - numerical parameters, data structure layouts, accessors, macros, - inline functions and templates. - -License: GPL-3 - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License version 3 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. - . - On Debian systems, the complete text of the GNU General - Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". - License: QPL-1.0 THE Q PUBLIC LICENSE version 1.0 diff --git a/debian/manpages b/debian/manpages new file mode 100644 index 0000000..5e407f9 --- /dev/null +++ b/debian/manpages @@ -0,0 +1 @@ +qps.1 diff --git a/debian/rules b/debian/rules index bbc2d07..98091cc 100755 --- a/debian/rules +++ b/debian/rules @@ -4,10 +4,5 @@ export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed %: - dh $@ --buildsystem=cmake --parallel - -override_dh_auto_install: - dh_auto_install -- DESTDIR=$(CURDIR)/debian/qps - -override_dh_strip: - dh_strip --dbg-package=qps-dbg + dh ${@} --buildsystem=cmake \ + --parallel diff --git a/icon/preferences-system.png b/icon/preferences-system.png deleted file mode 100644 index a8103d82ea7437f9b457475782d08ce479cfc1d8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2868 zcmV-43(NG0P)z^Q>-8KIssI20AY({UO#lFHH2?s0HvjFc3h|e-=V%E)639B}=eJ21>y^ z?BX&_8YE=!v_NQn>v$J3d0eSgDig?UC*0Z>&w00030|5T2#3VG!&S{q&c01E;u;Wbo}w;l(lfbpI9lNH9uU@ePtglR6O0a#N4tx3mOi!B5Y!FvyY zG3_Jv7(s-t>+9mmx!io*00030|BR4L3W7iYg+H;f(Q+|R`%Y2E@f02`=nU=Mhqlwg zC@jZOCtC=K(4x0|yvO^o0J+)ja=Bi8$=l`1aev?!CV&-ZDN}z5QUVZXDN1VqTrsCq z)i@g9-ZXeY(8op*P2JKOgHn1B+xB26@|+?J0qB&XH3oo%=kk1&{d>j?hDz&ES0Mxd zjx)o&yU}RBHr<0ia88ob2LJ&7|BRDQO2c3f#eezJWYa~lDY~l{aFG*;h!;>1mlcHG zMhZo7A=Dxs!BsXMLtG^n&_$}W^W~e*MKo=|MF$4v4R7EL^Tq=XfC1aZtGD=Cxx>rz zR`=!M@n81dZhz!g)*`A%uUDrkm9-Im~PH$%N_I|acH9me=EuWP}f*_3l zI^EG3Cn}Qc`fu+dEQsJ^cve(A$?kezqT<1;Zym)#bbVc4O?Q7)BY?rntLwT~7@6T6&2bz?hldswP$+#EpBec)%lzCN zjE!}ppPo3Y*YT^T-H8SVVmSqw^=7jP@KFJ19UW>b2;ly{Z&e8{ZAOJuDnD6WTkqRr z?8fJRaW5$rU!CM*e*zO?OxQDK2}~Hh_2*U#;W()2Y1G03LMb|0qiZ#U?_1pQ(O)*d zZrCJSiET$j`pwmJ7KC)H=r9f+p@6$2H;!aPh{Q3P0r6f{HZW|3I zCZ`C)5Mwk4KPq^h_d*cHm01a$pGRIQMI}8vK)Y>mJG*HxnFLB9rR*8A1c|ndF>i_|-2>7D zN~)eQAo^=?U5EYh_M6G~%iFlF+vNz!#+PrsWAU8I0iS?LK)z$QXaX1iSucOrD1s=C ze`aOs(uWCh4y~u&EetU zFu9IDzkh8SV=jfj#6jnP%QvnwIhkLeo6RO4UakEXz|_>~3qUyptf(+vsUWpluJgFH zh)O;!7qDsU-z$Y8N)$yzBKbXv5YgPeva*6`zHNXioCs`g7A`qC`kCESMMX3A0jhBE zUjk6CXJ^^k@=TfmRz*}Zc9#ZF(LN95o#rS)Me|o6>ihBc{SaviV0#-oI*N(8MY~(%!As8FuXmxc^$Sf{;=^-MVo0;~u`*E?E=m~C~J%7Q~g=^m5 zhsZex)?!K}jt9wU1zV3Ztx?06KM-(~g^}65qfe`sDXt#;h*D-T*@n#9M+kVMG5b)sPBR|30 zwbv{zEzybZ6XkNbm%15%Bzv6emCZCab-Vt9k&zM3oSpHeQ{xlN&er_h!=H^bKss-I zYcz&JdcG#-p49pI-g9H4u;v!kLnieLj?cvGs^g|^WD!3!Z3 zM8V5cdl4b^&JTn}TT0S2X(_XsQN6(3CZJ`0xP$fBpG8+r>ai za>|r;N;poLT&{zYZ@rD|Yq}Ls6oe3{ZEbi*j!?XM6?0+&>+D&~n>Vq}oC)7E7cb&D z4nosnv$(Uf!`%ElAAU5FIHO+=yjgd~fBAWw*WVZjWmb87B?)LdjuUyxg#zV`4IH4f zyzJX2Pa^N-jSb3$0tDm8k8RuBpS}0OdH??GJ?wxu$bN=*PQdWO()yTXSq!}Y9*M1943CUN zu3IYD-!x5f9UU|`w}gf4a8G-*kjarna=9m2qjzrA(a1l z1**9JOI-m?)9TavMh;d3Up7icon/vcross.png icon/pause.png icon/superman.png - icon/preferences-system.png diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index db29ac4..ea4f847 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,7 @@ set(SOURCES proc.cpp + qpsapp.cpp qps.cpp screenshot.cpp pstable.cpp @@ -14,6 +15,14 @@ set(SOURCES lookup.cpp details.cpp command.cpp + commandutils.cpp + commandmodel.cpp + commanddialog.cpp + checkboxdelegate.cpp + execwindow.cpp + watchcond.cpp + listmodel.cpp + watchdogdialog.cpp misc.cpp trayicon.cpp htable.cpp @@ -23,6 +32,7 @@ set(SOURCES ) SET(HEADERS + qpsapp.h qps.h screenshot.h pstable.h @@ -32,7 +42,16 @@ SET(HEADERS infobar.h lookup.h details.h + tablefield.h command.h + commandutils.h + commandmodel.h + commanddialog.h + checkboxdelegate.h + execwindow.h + watchcond.h + listmodel.h + watchdogdialog.h misc.h trayicon.h htable.h @@ -46,6 +65,7 @@ set(UIS message.ui ) +set(RESOURCES "../qps.qrc") #----------------------------------------------------------------------------- # Translations #----------------------------------------------------------------------------- @@ -69,22 +89,23 @@ lxqt_translate_desktop(DESKTOP_FILES #----------------------------------------------------------------------------- -add_executable(${PROJECT} +add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${UIS} ${QM_FILES} ${QM_LOADER} ${DESKTOP_FILES} + ${RESOURCES} ) -target_link_libraries(${PROJECT} +target_link_libraries(${PROJECT_NAME} Qt5::Widgets Qt5::X11Extras Qt5::DBus ) -install(TARGETS ${PROJECT} RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}) +install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}) install(FILES ${DESKTOP_FILES} DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications" diff --git a/src/checkboxdelegate.cpp b/src/checkboxdelegate.cpp new file mode 100644 index 0000000..82dd4f3 --- /dev/null +++ b/src/checkboxdelegate.cpp @@ -0,0 +1,94 @@ +// checkboxdelegate.cpp +// +// This program is free software. See the file COPYING for details. +// Author: Mattias Engdeg?rd, 1997-1999 + +#include "checkboxdelegate.h" + +#include +checkBoxDelegate::checkBoxDelegate(QObject *parent) : QItemDelegate(parent) {} +//! [0] + +//! [1] +QWidget *checkBoxDelegate::createEditor(QWidget *parent, + const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + printf("createEditor\n"); + // return 0; + if (index.column() == 1) + { + QSpinBox *editor = new QSpinBox(parent); + editor->setMinimum(0); + editor->setMaximum(100); + return editor; + } + return QItemDelegate::createEditor(parent, option, index); + return 0; +} +//! [1] + +//! [2] +void checkBoxDelegate::setEditorData(QWidget *editor, + const QModelIndex &index) const +{ + printf("setEditorData\n"); + return; + // if(index + if (index.column() == 1) + { + int value = index.model()->data(index, Qt::EditRole).toInt(); + // int value=0; + QSpinBox *spinBox = static_cast(editor); + spinBox->setValue(value); + } +} +//! [2] + +//! [3] +void checkBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const +{ + printf("setModelData\n"); + return; + if (index.column() == 1) + { + QSpinBox *spinBox = static_cast(editor); + spinBox->interpretText(); + int value = spinBox->value(); + model->setData(index, value, Qt::EditRole); + } +} +//! [3] + +//! [4] +void checkBoxDelegate::updateEditorGeometry(QWidget *editor, + const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + printf("updateEditorGeometry\n"); + // if(index.column()==1) + editor->setGeometry(option.rect); +} +//! [4] + +void checkBoxDelegate::paint(QPainter *painter, + const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + printf("paint\n"); + if (index.column() == 1) + { + QVariant value = 0; // index.model()->data(index, Qt::UserRole); + /* if (!isSupportedType(value.type())) { + QStyleOptionViewItem myOption = option; + myOption.state &= ~QStyle::State_Enabled; + QItemDelegate::paint(painter, myOption, index); + return; + } */ + } + QItemDelegate::paint(painter, option, index); +} +// QSize QAbstractItemDelegate::sizeHint ( const QStyleOptionViewItem & option, +// const QModelIndex & index ) const [pure virtual] + diff --git a/src/checkboxdelegate.h b/src/checkboxdelegate.h new file mode 100644 index 0000000..a73d2d2 --- /dev/null +++ b/src/checkboxdelegate.h @@ -0,0 +1,30 @@ +// checkboxdelegate.h +// +// This program is free software. See the file COPYING for details. +// Author: Mattias Engdeg?rd, 1997-1999 + + +#ifndef CHECKBOXDELEGATE_H +#define CHECKBOXDELEGATE_H + +#include +class checkBoxDelegate : public QItemDelegate +// class checkBoxDelegate : public QAbstractItemDelegate +{ + Q_OBJECT + public: + checkBoxDelegate(QObject *parent = 0); + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, + const QModelIndex &index) const; + void setEditorData(QWidget *editor, const QModelIndex &index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const; + void updateEditorGeometry(QWidget *editor, + const QStyleOptionViewItem &option, + const QModelIndex &index) const; + + void paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const; +}; + +#endif // CHECKBOXDELEGATE_H diff --git a/src/command.cpp b/src/command.cpp index 1f2b6d2..bb46237 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -7,15 +7,15 @@ #include #include -#include #include -#include -#include -#include -#include -#include #include "command.h" +#include "commandutils.h" +#include "checkboxdelegate.h" +#include "watchcond.h" +#include "execwindow.h" +#include "listmodel.h" +#include "watchdogdialog.h" #include "qps.h" #include "proc.h" #include "uidstr.h" @@ -25,71 +25,6 @@ extern Qps *qps; extern ControlBar *controlbar; extern QList commands; -int find_command(QString s) -{ - for (int i = 0; i < commands.size(); i++) - if (s == commands[i]->name) - return i; - return -1; -} - -// DEL has "&" end of the string ? -bool hasAmpersand(QString cmdline) -{ - QString str; - int len; - str = cmdline.simplified(); - - if (str == "%update") - return true; // internal command - - len = str.length(); - if (str[len - 1] == '&') - return true; - else - return false; -} - -void check_command(int idx) {} - -// -void check_commandAll() -{ - int i, idx; - - return; - for (int i = 0; i < commands.size(); i++) - { - if (hasAmpersand(commands[i]->cmdline) == false) - commands[i]->cmdline.append("&"); - } -} - -// after read ~/.qpsrc -void add_default_command() -{ - - int idx; - - /* - idx=find_command("Update"); - if (idx>=0) - commands[idx]->cmdline="%update"; - else - commands.add(new Command("Update","%update",true)); - */ - - /* - * PAUSED - idx=find_command("Quit"); - if (idx>=0) - commands[idx]->cmdline="killall qps"; - else commands.add(new Command("Quit","killall qps",false)); - */ - - // check_commandAll(); DEL? -} - Command::Command(QString n, QString cmd, bool flag) { // printf("Command init\n"); @@ -108,74 +43,6 @@ Command::Command(QString n, QString cmd, bool flag) // SLOT(exec_command())); } -QString watchCond::getVal(QString &str, const char *key) -{ - int n; // key.length(); - int idx = str.indexOf(key); - if (idx < 0) - return "cant' found"; - - idx = str.indexOf("[", idx); - if (idx < 0) - return "[ error"; - int idx_end = str.indexOf("]", idx); - if (idx_end < 0) - return "] error"; - n = idx_end - idx; - return str.mid(idx + 1, n - 1); -} -QString watchCond::getstring() -{ - QString string; - string.clear(); - switch (cond) - { - case WATCH_PROCESS_FINISH: - string.append("if process [" + procname + "] finish, "); - // string=string.sprintf("if process [%s] finish",procname); - break; - case WATCH_PROCESS_START: - string.append("if process [" + procname + "] start, "); - break; - case WATCH_SYS_CPU_OVER: - string.append("if sys_cpu over [" + QString::number(cpu) + "], "); - break; - case WATCH_SYS_CPU_UNDER: - string.append("if sys_cpu under [" + QString::number(cpu) + "], "); - break; - default: - ; - } - if (!command.isEmpty()) - string.append("exec [" + command + "] "); - if (!message.isEmpty()) - string.append("showmsg [" + message + "] "); - if (enable) - string.append("enabled"); - else - string.append("disabled"); - - return string; -} -void watchCond::putstring(QString str) -{ - if (str.contains("if process")) - { - if (str.contains("start")) - cond = WATCH_PROCESS_START; - if (str.contains("finish")) - cond = WATCH_PROCESS_FINISH; - procname = getVal(str, "if process"); - } - if (str.contains("exec")) - command = getVal(str, "exec"); - if (str.contains("showmsg")) - message = getVal(str, "showmsg"); - if (str.contains("enabled")) - enable = true; - else - enable = false; -} Command::~Command() { // toolbutton->hide(); @@ -352,277 +219,8 @@ void Command::call(Procinfo *p) } } -CommandDialog::CommandDialog() -{ - setWindowTitle("Edit Commands 0.1 alpha"); - // setWindowFlags(Qt::WindowStaysOnTopHint); - - QHBoxLayout *hbox = new QHBoxLayout(this); // TOP - CommandModel *cmdModel = new CommandModel(this); - // item list - listview = new QListView(this); - listview->setModel(cmdModel); - listview->setFixedWidth(fontMetrics().width("0") * 16); - hbox->addWidget(listview); - - QVBoxLayout *vbox = new QVBoxLayout; // TOP-> RIGHT - hbox->addLayout(vbox); - - QHBoxLayout *h1 = new QHBoxLayout; - vbox->addLayout(h1); - QLabel *l1 = new QLabel("Name:", this); - h1->addWidget(l1); - name = new QLineEdit(this); - name->setMinimumWidth(170); - name->setText(""); - h1->addWidget(name); - - QHBoxLayout *hbox2 = new QHBoxLayout; - vbox->addLayout(hbox2); - // qcheck1 = new QCheckBox (this); - // qcheck1->setText("Toolbar"); - // qcheck1->setEnabled(false); - // hbox2->addWidget(qcheck1); - if (0) - { - qcheck2 = new QCheckBox(this); - qcheck2->setText("Popup"); - qcheck2->setEnabled(false); - hbox2->addWidget(qcheck2); - } - - QLabel *l2 = new QLabel("Command Line:", this); - l2->setFixedHeight(l2->sizeHint().height()); - l2->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); - vbox->addWidget(l2); - - cmdline = new QLineEdit(this); - cmdline->setFixedHeight(cmdline->sizeHint().height()); - cmdline->setMinimumWidth(250); - cmdline->setText(""); - vbox->addWidget(cmdline); - - QLabel *l3 = new QLabel("Substitutions:\n" - "%p\tPID\n" - "%c\tCOMMAND\n%C\tCMDLINE\n%u\tUSER\n" - "%%\t%\n" - "\n", - this); - - l3->setFrameStyle(QFrame::Panel); - l3->setFrameShadow(QFrame::Sunken); - l3->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); // | Qt::ExpandTabs); - vbox->addWidget(l3); - - QHBoxLayout *hl = new QHBoxLayout; - vbox->addLayout(hl); - new0 = new QPushButton("New...", this); - hl->addWidget(new0); - add = new QPushButton("Add...", this); - hl->addWidget(add); - del = new QPushButton("Delete", this); - hl->addWidget(del); - button_ok = new QPushButton("Close", this); - hl->addWidget(button_ok); - - connect(listview, SIGNAL(clicked(const QModelIndex &)), - SLOT(set_select(const QModelIndex &))); - connect(new0, SIGNAL(clicked()), SLOT(new_cmd())); - connect(add, SIGNAL(clicked()), SLOT(add_new())); - connect(del, SIGNAL(clicked()), SLOT(del_current())); - connect(button_ok, SIGNAL(clicked()), SLOT(close())); - connect(name, SIGNAL(textChanged(const QString &)), - SLOT(event_name_midified(const QString &))); - connect(cmdline, SIGNAL(textChanged(const QString &)), - SLOT(event_cmd_modified())); - // connect(qcheck1, SIGNAL(toggled ( bool ) ), - // SLOT(event_toolbar_checked(bool - // ))); - - TBloon *bloon = new TBloon(this); - /// for(int i = 0; i < commands.size(); i++) - /// listview->insertItem(commands[i]->name); - // listview->addItem(commands[i]->name); - /// vbox->freeze(); -} - -// DEL -void CommandDialog::event_toolbar_checked(bool on) -{ - // name->text(); - int idx = find_command(name->text()); - if (idx >= 0) - commands[idx]->toolbar = on; - - /// controlbar->update_bar(); -} - -void CommandDialog::event_name_midified(const QString &new_name) -{ - int idx; - FUNC_START; - // printf("debug:changed_description() start \n"); - idx = find_command(new_name); - if (idx == -1) - { - add->setEnabled(1); - } - else - add->setEnabled(0); - - // printf("debug:changed_description() end \n"); -} - -// if modified then call this function -void CommandDialog::event_cmd_modified() -{ - int idx; - // if(name->text()=="") return; - if (find_command(name->text()) < 0) - return; - - idx = find_command(name->text()); - - commands[idx]->name = name->text(); - commands[idx]->cmdline = cmdline->text(); - emit command_change(); -} - -// set the description,cmdline from current selected QListBox item -void CommandDialog::set_buttons(int index) -{ - if (index < 0) - { - new_cmd(); - return; - } - /* - //bool sel = (lb->currentRow() >= 0); - Command *c ; - if(sel) - //c = commands[find_command(lb->currentText())]; - c = commands[find_command(lb->currentText())]; - else - c = commands[find_command(lb->text(index))]; - name->setText(c->name); - cmdline->setText(c->cmdline); - del->setEnabled(sel); - */ -} - -// called when clicked ! -void CommandDialog::set_select(const QModelIndex &index) -{ - Command *c = - static_cast(index.internalPointer()); // never Null ? - /* - if (item==NULL) return; // important - Command *c = commands[find_command(item->text())]; - */ - name->setText(c->name); - cmdline->setText(c->cmdline); - // DEL qcheck1->setChecked(c->toolbar); - // qcheck2->setChecked(c->popup); - - // bool sel = (listview->currentItem() >= 0); - if (c->name == "Update") - del->setEnabled(false); - else - del->setEnabled(true); -} - -void CommandDialog::reset() -{ - listview->reset(); - name->setText(""); - cmdline->setText(""); - add->setText("Add..."); - add->setEnabled(0); - button_ok->setEnabled(1); - listview->clearSelection(); -} - -void CommandDialog::new_cmd() -{ - reset(); - add->setEnabled(1); - name->setFocus(); -} - -void CommandDialog::add_new() -{ - if (name->text() == "") - return; - - // commands.add(new Command(name->text(), - // cmdline->text(),qcheck1->isChecked - // () )); - commands.append(new Command(name->text(), cmdline->text(), false)); - check_commandAll(); // TEMP - - listview->reset(); - add->setEnabled(0); - del->setEnabled(0); - button_ok->setEnabled(1); - - emit command_change(); // notice to refresh Qps::make_command_menu() - // control_bar->update_bar(); // ** important -} - -void CommandDialog::del_current() -{ - int idx = find_command(name->text()); - if (idx >= 0) - { - // printf("del\n"); - commands.removeAt(idx); - listview->reset(); // listview->reset(); - // control_bar->update_bar(); - emit command_change(); // notice to refresh menu_commands - } -} - -// CommandModel -CommandModel::CommandModel(QObject *parent) {} -CommandModel::~CommandModel() {} - -QModelIndex CommandModel::index(int row, int column, - const QModelIndex &parent) const -{ - if (row >= 0 and column >= 0 and row < commands.size() and column < 1) - { - Command *cmd = commands[row]; - return createIndex(row, column, cmd); - } - else - return QModelIndex(); -} -QModelIndex CommandModel::parent(const QModelIndex &child) const -{ - return QModelIndex(); -} -int CommandModel::rowCount(const QModelIndex &parent) const -{ - return commands.size(); -} -// int CommandModel::columnCount(const QModelIndex &parent) const{return 1;}; -QVariant CommandModel::data(const QModelIndex &index, int role) const -{ - if (role == Qt::DisplayRole) - { - Command *cmd = static_cast(index.internalPointer()); - return cmd->name; - } - if (role == Qt::DecorationRole) - { - } - return QVariant(); -} -void CommandModel::update() {} // TEMP - //---------------------------------------------------------------- QList watchlist; -QList execlist; extern WatchdogDialog *watchdogDialog; @@ -689,509 +287,3 @@ void watchdog_syscpu(int cpu) // QMessageBox::warning(0, "Watchdog", "aaaaa"); //blocking } } - -// ExecWindow -ExecWindow::ExecWindow() -{ - setupUi(this); - // connect(okButton, SIGNAL(clicked()), this, SLOT(close())); - // show(); -} - -ExecWindow::~ExecWindow() {} - -// eventcat_id; -ExecWindow::ExecWindow(watchCond *wc, int pid, QString cmd) -{ - setupUi(this); - setWindowTitle("Qps Watchdog"); - - wcond = wc; - - QString str; - - if (wc->cond == WATCH_PROCESS_START) - { - textEdit->append(cmd + "(" + QString::number(pid) + ")" + " start"); - } - if (wc->cond == WATCH_PROCESS_FINISH) - textEdit->append(cmd + "(" + QString::number(pid) + ")" + " finished"); - - flag_started = false; - - pr = new QProcess; // leak? - if (!wc->command.isEmpty()) // conflict pid's command - { - pr->start(wc->command); // thread run, if null then segfault occurs. ? - } - - connect(okButton, SIGNAL(clicked()), this, SLOT(cmd_ok())); - - connect(pr, SIGNAL(started()), this, SLOT(cmd_started())); - connect(pr, SIGNAL(finished(int, QProcess::ExitStatus)), this, - SLOT(cmd_finished(int, QProcess::ExitStatus))); - connect(pr, SIGNAL(error(QProcess::ProcessError)), this, - SLOT(cmd_error(QProcess::ProcessError))); - - show(); - - execlist.append(this); -} - -ExecWindow::ExecWindow(QString str, QString exec_cmd, int pid, QString cmd) -{ - setupUi(this); - // -} - -// QProcess: Destroyed while process is still running.(Segmentation fault) -void ExecWindow::cmd_ok() -{ - if (pr->state() == QProcess::Running) - { - // pr->kill(); - pr->terminate(); - return; - } - close(); // Qt::WA_DeleteOnClose -} - -// slot : catch terminate signal. -void ExecWindow::cmd_finished(int exitCode, QProcess::ExitStatus exitStatus) -{ - textEdit->append(wcond->command + " exit with code " + - QString::number(exitStatus)); - okButton->setText("Close"); - delete pr; -} - -void ExecWindow::cmd_started() -{ - textEdit->append(wcond->command + " [running]"); - okButton->setText("terminate command"); - flag_started = true; -} - -void ExecWindow::cmd_error(QProcess::ProcessError e) -{ - // not found command - // Error ? : - if (e == QProcess::FailedToStart) - // textEdit->append("Error : command not found [" + - // command + "]" + "(code - //" + QString::number(e) + ")" ); - textEdit->append("Error " + QString::number(e) + " : [" + - wcond->command + "] Maybe command not found"); - delete pr; -} - -void ExecWindow::setText(QString str) -{ - textEdit->append(str); - // label->setText(str); -} - -WatchdogDialog::WatchdogDialog() -{ - setupUi(this); - listmodel = new ListModel(); - - tableView->setModel(listmodel); - checkBoxDelegate delegate; - tableView->setEditTriggers(QAbstractItemView::SelectedClicked); - /// tableView->setItemDelegate(&delegate); - - tableView->setSelectionBehavior(QAbstractItemView::SelectRows); - tableView->setSelectionMode(QAbstractItemView::SingleSelection); - QHeaderView *h = tableView->verticalHeader(); - h->setVisible(false); - - QHeaderView *v = tableView->horizontalHeader(); -#if QT_VERSION >= 0x050000 - v->setSectionResizeMode(0, QHeaderView::Stretch); - v->setSectionResizeMode(1, QHeaderView::ResizeToContents); -#endif - // v->setClickable (false); - connect(newButton, SIGNAL(clicked()), this, SLOT(_new())); - connect(closeButton, SIGNAL(clicked()), this, SLOT(apply())); - connect(addButton, SIGNAL(clicked()), this, SLOT(add())); - connect(delButton, SIGNAL(clicked()), this, SLOT(del())); - connect(comboBox, SIGNAL(activated(int)), SLOT(comboChanged(int))); - connect(comboBox, SIGNAL(highlighted(const QString &)), - SLOT(condChanged(const QString &))); - - connect(tableView, SIGNAL(clicked(const QModelIndex &)), - SLOT(eventcat_slected(const QModelIndex &))); - connect(message, SIGNAL(textEdited(const QString &)), - SLOT(Changed(const QString &))); - connect(command, SIGNAL(textEdited(const QString &)), - SLOT(Changed(const QString &))); - connect(proc_name, SIGNAL(textEdited(const QString &)), - SLOT(Changed(const QString &))); - connect(comboBox, SIGNAL(activated(const QString &)), - SLOT(Changed(const QString &))); - - checkBox_alreadyrun->hide(); - listView->hide(); - spinBox->hide(); - label_cpu->hide(); - /// printf("close ...\n"); - // tableView->update(); - // listmodel->update(); // meaningless.. - - TBloon *bloon = new TBloon(this); - return; -} - -void WatchdogDialog::showEvent(QShowEvent *event) -{ - // Qt 4.4.0 bug? - // printf("show!!!!!!!!!\n"); - listmodel->update(); -} -void WatchdogDialog::comboChanged(int idx) -{ - - // itemText(idx); - QString str = comboBox->currentText(); - - if (str.contains("cpu")) - { - label_cpu->show(); - spinBox->show(); - } - else - { - spinBox->hide(); - label_cpu->hide(); - } - - if (str.contains("process")) - { - label_procname->show(); - proc_name->show(); - } - else - { - label_procname->hide(); - proc_name->hide(); - } - - if (message->text().isEmpty()) - { - // if(str.contains("start")) message->setText("%CMD start - // with pid %PID"); - // if(str.contains("finish")) message->setText("%CMD - // finish with pid - //%PID"); - } -} - -void WatchdogDialog::eventcat_slected(const QModelIndex &idx) -{ - - watchCond *w = watchlist[idx.row()]; - // printf("row=%d\n",at=idx.row()); - - if (idx.column() == 1) - { - w->enable = !(w->enable); - listmodel->update(idx.row()); - return; - } - - QString str = idx.data().toString(); // Qt::DisplayRol - - if (str.contains("process")) - proc_name->setText(w->procname); - else - proc_name->setText(""); - if (str.contains("cpu")) - spinBox->setSingleStep(w->cpu); - else - spinBox->setSingleStep(50); - if (str.contains("exec")) - command->setText(w->command); - else - command->setText(""); - if (str.contains("showmsg")) - message->setText(w->message); - else - message->setText(""); - - checkCombo(); - comboBox->setCurrentIndex(w->cond); -} - -void WatchdogDialog::Changed(const QString &str) -{ - QModelIndex idx = tableView->currentIndex(); - // QModelIndexList list=tableView->selectedIndexes (); - bool flag = tableView->selectionModel()->hasSelection(); - // if(list.count() and idx.isValid()) - if (flag and idx.isValid()) - { - int at = idx.row(); - watchCond *w = watchlist[at]; - w->message = message->text(); - w->command = command->text(); - w->procname = proc_name->text(); - w->cond = comboBox->currentIndex(); - listmodel->update(at); - // watchlist.removeAt(at); - } - // listmodel->update(); -} - -void WatchdogDialog::checkCombo() -{ - if (comboBox->count() == 1) - { - comboBox->clear(); - comboBox->addItem("if process start"); - comboBox->addItem("if process finish"); - return; - } -} - -// comboChanged() -> checkCombo() -void WatchdogDialog::condChanged(const QString &str) -{ - checkCombo(); - // what is this? - // printf("chagend\n"); - // comboBox->currentText(); - // command->text(); - // message->text(); -} - -void WatchdogDialog::_new() -{ - tableView->clearSelection(); - proc_name->clear(); - command->clear(); - message->clear(); - comboBox->clear(); - comboBox->addItem("select condition"); -} - -void WatchdogDialog::add() -{ - watchCond *w = new watchCond; - w->enable = true; - w->cond = comboBox->currentIndex(); - w->command = command->text(); - w->message = message->text(); - w->procname = proc_name->text(); - watchlist.append(w); - // listView->update(QModelIndex()); - // listView->reset(); - // tableView->reset(); - // listmodel->insertRow(listmodel->rowCount(QModelIndex())); - // tableView->update(QModelIndex()); - // tableView->dataChanged(QModelIndex(),QModelIndex()); //protected - listmodel->update(); -} - -void WatchdogDialog::del() -{ - // QModelIndex idx=listView->currentIndex(); - QModelIndex idx = tableView->currentIndex(); - if (idx.isValid()) - { - int at = idx.row(); - watchlist.removeAt(at); - } - listmodel->update(); - tableView->setCurrentIndex(idx); -} - -void WatchdogDialog::apply() -{ - qps->write_settings(); - close(); -} - -QModelIndex ListModel::index(int row, int column, - const QModelIndex &parent) const -{ - // printf("index %d %d\n",row,column); - if (row >= 0 and column >= 0 and row < watchlist.size()) - { - if (column < 2) - { - watchCond *item = watchlist[row]; - return createIndex(row, column, item); - } - } - return QModelIndex(); -} - -void ListModel::update(int row) -{ - emit dataChanged(index(row, 0), index(row, 1)); -} - -void ListModel::update(const QModelIndex &idx) { emit dataChanged(idx, idx); } - -// Pure Virtual -QModelIndex ListModel::parent(const QModelIndex &child) const -{ - return QModelIndex(); // no parent! -} -int ListModel::rowCount(const QModelIndex &parent) const -{ - return watchlist.size(); -} -QVariant ListModel::headerData(int section, Qt::Orientation orientation, - int role) const -{ - // printf("headerData\n"); - if (role == Qt::DisplayRole) - { - if (section == 0) - return QString("Event Category"); - if (section == 1) - return QString("Enable"); - } - /* - if (role == Qt::FontRole) - { - QFont f=QFont(); - f.setBold(false); - return f; - } */ - if (role == Qt::SizeHintRole) - { - // return QSize(18,18); - } - return QVariant(); -} - -QVariant ListModel::data(const QModelIndex &index, int role) const -{ - // printf("data\n"); - watchCond *item = static_cast(index.internalPointer()); - if (index.column() == 0) - { - if (role == Qt::DisplayRole) - { - return QString(item->getstring()); - } - if (role == Qt::DecorationRole) - { - } - if (role == Qt::EditRole) - { - } - } - - if (index.column() == 1) - { - if (role == Qt::CheckStateRole) - { - if (item->enable) - return Qt::Checked; - else - return Qt::Unchecked; - } - if (role == Qt::TextAlignmentRole) - return Qt::AlignRight; - if (role == Qt::EditRole) - { - } - } - if (role == Qt::SizeHintRole) - { - // return QSize(18,18); - } - return QVariant(); -} -// void CommandModel::update(){} //TEMP - -#include -checkBoxDelegate::checkBoxDelegate(QObject *parent) : QItemDelegate(parent) {} -//! [0] - -//! [1] -QWidget *checkBoxDelegate::createEditor(QWidget *parent, - const QStyleOptionViewItem &option, - const QModelIndex &index) const -{ - printf("createEditor\n"); - // return 0; - if (index.column() == 1) - { - QSpinBox *editor = new QSpinBox(parent); - editor->setMinimum(0); - editor->setMaximum(100); - return editor; - } - return QItemDelegate::createEditor(parent, option, index); - return 0; -} -//! [1] - -//! [2] -void checkBoxDelegate::setEditorData(QWidget *editor, - const QModelIndex &index) const -{ - printf("setEditorData\n"); - return; - // if(index - if (index.column() == 1) - { - int value = index.model()->data(index, Qt::EditRole).toInt(); - // int value=0; - QSpinBox *spinBox = static_cast(editor); - spinBox->setValue(value); - } -} -//! [2] - -//! [3] -void checkBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const -{ - printf("setModelData\n"); - return; - if (index.column() == 1) - { - QSpinBox *spinBox = static_cast(editor); - spinBox->interpretText(); - int value = spinBox->value(); - model->setData(index, value, Qt::EditRole); - } -} -//! [3] - -//! [4] -void checkBoxDelegate::updateEditorGeometry(QWidget *editor, - const QStyleOptionViewItem &option, - const QModelIndex &index) const -{ - printf("updateEditorGeometry\n"); - // if(index.column()==1) - editor->setGeometry(option.rect); -} -//! [4] - -void checkBoxDelegate::paint(QPainter *painter, - const QStyleOptionViewItem &option, - const QModelIndex &index) const -{ - printf("paint\n"); - if (index.column() == 1) - { - QVariant value = 0; // index.model()->data(index, Qt::UserRole); - /* if (!isSupportedType(value.type())) { - QStyleOptionViewItem myOption = option; - myOption.state &= ~QStyle::State_Enabled; - QItemDelegate::paint(painter, myOption, index); - return; - } */ - } - QItemDelegate::paint(painter, option, index); -} -// QSize QAbstractItemDelegate::sizeHint ( const QStyleOptionViewItem & option, -// const QModelIndex & index ) const [pure virtual] diff --git a/src/command.h b/src/command.h index ef603d7..9cde651 100644 --- a/src/command.h +++ b/src/command.h @@ -1,7 +1,7 @@ // command.h emacs, this is written in -*-c++-*- // // This program is free software. See the file COPYING for details. -// Author: Mattias Engdegård, 1997-1999 +// Author: Mattias Engdeg�rd, 1997-1999 #ifndef COMMAND_H #define COMMAND_H @@ -18,8 +18,7 @@ #include "proc.h" #include "misc.h" -int find_command(QString s); -void add_default_command(); +class ListModel; class Command { @@ -41,186 +40,4 @@ class Command bool popup; }; -class CommandModel : public QAbstractItemModel -{ - Q_OBJECT - public: - CommandModel(QObject *parent = 0); - ~CommandModel(); - QModelIndex index(int row, int column, const QModelIndex &parent) const; - QModelIndex parent(const QModelIndex &child) const; - int rowCount(const QModelIndex &parent) const; - int columnCount(const QModelIndex &parent) const { return 1; }; - QVariant data(const QModelIndex &index, int role) const; - // Qt::ItemFlags flags(const QModelIndex &index) const; - void update(); // TEMP -}; - -// class CommandDialog : public QWidget -class CommandDialog : public QDialog -{ - Q_OBJECT - public: - CommandDialog(); - -signals: - void command_change(); - - protected slots: - void new_cmd(); - void add_new(); - void del_current(); - void set_buttons(int); - void reset(); - void set_select(const QModelIndex &); - void event_name_midified(const QString &new_name); - void event_cmd_modified(); - void event_toolbar_checked(bool); - - private: - QListView *listview; - QPushButton *new0, *add, *del, *edit, *button_ok; - QLineEdit *name, *cmdline; - QCheckBox *qcheck1; - QCheckBox *qcheck2; -}; - -#include -class checkBoxDelegate : public QItemDelegate -// class checkBoxDelegate : public QAbstractItemDelegate -{ - Q_OBJECT - public: - checkBoxDelegate(QObject *parent = 0); - QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, - const QModelIndex &index) const; - void setEditorData(QWidget *editor, const QModelIndex &index) const; - void setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const; - void updateEditorGeometry(QWidget *editor, - const QStyleOptionViewItem &option, - const QModelIndex &index) const; - - void paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const; -}; - -#include -// class ListModel : public QAbstractItemModel -class ListModel : public QAbstractTableModel -// class ListModel : public QStandardItemModel -{ - Q_OBJECT - public: - ListModel(QObject *parent = 0){}; - ~ListModel(){}; - QModelIndex index(int row, int column, - const QModelIndex &parent = QModelIndex()) const; // pure - QModelIndex parent(const QModelIndex &child) const; // pure virtual - int rowCount(const QModelIndex &parent) const; - int columnCount(const QModelIndex &parent) const { return 2; }; - QVariant data(const QModelIndex &index, int role) const; - QVariant headerData(int section, Qt::Orientation o, int role) const; - // QMap itemData ( const QModelIndex & index ) const - //; - void update() - { // reset(); - } - void update(const QModelIndex &idx); - void update(int row); - // Qt::ItemFlags flags(const QModelIndex &index) const; - // void update(); //TEMP -}; - -#include "ui_watchdog.h" -class WatchdogDialog : public QDialog, private Ui_EventDialog -{ - Q_OBJECT - public: - WatchdogDialog(); - ListModel *listmodel; - // signals: - // void command_change(); - void checkCombo(); - protected slots: - void _new(); - void apply(); - void add(); - void del(); - void condChanged(const QString &str); - void Changed(const QString &str); - - void comboChanged(int); - void eventcat_slected(const QModelIndex &idx); - - protected: - virtual void showEvent(QShowEvent *event); - - // void set_select( const QModelIndex & ); - // void event_name_midified(const QString &new_name); - // void event_cmd_modified(); - // void event_toolbar_checked(bool); - private: -}; - -#define WATCH_PROCESS_START 0 -#define WATCH_PROCESS_FINISH 1 -#define WATCH_PROCESS_CPU_OVER 2 -#define WATCH_SYS_CPU_OVER 3 -#define WATCH_SYS_CPU_UNDER 4 - -// if process [name] start, exec [command], showmsg [xxx] -// if process [name] finish exec [command], showmsg [xxx] -// if system cpu over [90%], exec [command], msg [xxx] -// if system cpu under [10%], exec [command], msg [xxx] -// if process [name] cpu over [90%] exec [command] msg [xxx] -// if process [name] start, kill_it, msg [xxx] -// if process [name] start, soundplay [ ], msg [xxx] - -class watchCond -{ - public: - int cond; - int enable; - int cpu; - QString procname; - QString command; - QString message; - - watchCond() - { - enable = 0; - // procname[0]=0; command[0]=0; - // message[0]=0; - } - // key [txt] [a] - // QString getVal(QString &str, QString &key) - QString getVal(QString &str, const char *key); - QString getstring(); - void putstring(QString str); -}; - -#include -#include "ui_message.h" -class ExecWindow : public QWidget, private Ui_ExecWindow -{ - Q_OBJECT - public: - ExecWindow(); - ExecWindow(QString str, QString exec_cmd, int pid = 0, QString cmd = ""); - ExecWindow(watchCond *wc, int pid = 0, QString cmd = ""); - ~ExecWindow(); - void setText(QString str); - QProcess *pr; - // QProcess proc; - QString execmd; - int flag_started; - watchCond *wcond; - protected slots: - void cmd_started(); - void cmd_finished(int exitCode, QProcess::ExitStatus exitStatus); - void cmd_error(QProcess::ProcessError error); - void cmd_ok(); -}; - #endif // COMMAND_H diff --git a/src/commanddialog.cpp b/src/commanddialog.cpp new file mode 100644 index 0000000..3aaf029 --- /dev/null +++ b/src/commanddialog.cpp @@ -0,0 +1,257 @@ +// commanddialog.cpp +// +// This program is free software. See the file COPYING for details. +// Author: Mattias Engdeg?rd, 1997-1999 + +#include "commanddialog.h" + +#include "qps.h" +#include "command.h" +#include "commandutils.h" +#include "commandmodel.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +extern QList commands; + +CommandDialog::CommandDialog() +{ + setWindowTitle("Edit Commands 0.1 alpha"); + // setWindowFlags(Qt::WindowStaysOnTopHint); + + QHBoxLayout *hbox = new QHBoxLayout(this); // TOP + CommandModel *cmdModel = new CommandModel(this); + // item list + listview = new QListView(this); + listview->setModel(cmdModel); + listview->setFixedWidth(fontMetrics().width("0") * 16); + hbox->addWidget(listview); + + QVBoxLayout *vbox = new QVBoxLayout; // TOP-> RIGHT + hbox->addLayout(vbox); + + QHBoxLayout *h1 = new QHBoxLayout; + vbox->addLayout(h1); + QLabel *l1 = new QLabel("Name:", this); + h1->addWidget(l1); + name = new QLineEdit(this); + name->setMinimumWidth(170); + name->setText(""); + h1->addWidget(name); + + QHBoxLayout *hbox2 = new QHBoxLayout; + vbox->addLayout(hbox2); + // qcheck1 = new QCheckBox (this); + // qcheck1->setText("Toolbar"); + // qcheck1->setEnabled(false); + // hbox2->addWidget(qcheck1); + if (0) + { + qcheck2 = new QCheckBox(this); + qcheck2->setText("Popup"); + qcheck2->setEnabled(false); + hbox2->addWidget(qcheck2); + } + + QLabel *l2 = new QLabel("Command Line:", this); + l2->setFixedHeight(l2->sizeHint().height()); + l2->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); + vbox->addWidget(l2); + + cmdline = new QLineEdit(this); + cmdline->setFixedHeight(cmdline->sizeHint().height()); + cmdline->setMinimumWidth(250); + cmdline->setText(""); + vbox->addWidget(cmdline); + + QLabel *l3 = new QLabel("Substitutions:\n" + "%p\tPID\n" + "%c\tCOMMAND\n%C\tCMDLINE\n%u\tUSER\n" + "%%\t%\n" + "\n", + this); + + l3->setFrameStyle(QFrame::Panel); + l3->setFrameShadow(QFrame::Sunken); + l3->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); // | Qt::ExpandTabs); + vbox->addWidget(l3); + + QHBoxLayout *hl = new QHBoxLayout; + vbox->addLayout(hl); + new0 = new QPushButton("New...", this); + hl->addWidget(new0); + add = new QPushButton("Add...", this); + hl->addWidget(add); + del = new QPushButton("Delete", this); + hl->addWidget(del); + button_ok = new QPushButton("Close", this); + hl->addWidget(button_ok); + + connect(listview, SIGNAL(clicked(const QModelIndex &)), + SLOT(set_select(const QModelIndex &))); + connect(new0, SIGNAL(clicked()), SLOT(new_cmd())); + connect(add, SIGNAL(clicked()), SLOT(add_new())); + connect(del, SIGNAL(clicked()), SLOT(del_current())); + connect(button_ok, SIGNAL(clicked()), SLOT(close())); + connect(name, SIGNAL(textChanged(const QString &)), + SLOT(event_name_midified(const QString &))); + connect(cmdline, SIGNAL(textChanged(const QString &)), + SLOT(event_cmd_modified())); + // connect(qcheck1, SIGNAL(toggled ( bool ) ), + // SLOT(event_toolbar_checked(bool + // ))); + + TBloon *bloon = new TBloon(this); + /// for(int i = 0; i < commands.size(); i++) + /// listview->insertItem(commands[i]->name); + // listview->addItem(commands[i]->name); + /// vbox->freeze(); +} + +// DEL +void CommandDialog::event_toolbar_checked(bool on) +{ + // name->text(); + int idx = find_command(name->text()); + if (idx >= 0) + commands[idx]->toolbar = on; + + /// controlbar->update_bar(); +} + +void CommandDialog::event_name_midified(const QString &new_name) +{ + int idx; + FUNC_START; + // printf("debug:changed_description() start \n"); + idx = find_command(new_name); + if (idx == -1) + { + add->setEnabled(1); + } + else + add->setEnabled(0); + + // printf("debug:changed_description() end \n"); +} + +// if modified then call this function +void CommandDialog::event_cmd_modified() +{ + int idx; + // if(name->text()=="") return; + if (find_command(name->text()) < 0) + return; + + idx = find_command(name->text()); + + commands[idx]->name = name->text(); + commands[idx]->cmdline = cmdline->text(); + emit command_change(); +} + +// set the description,cmdline from current selected QListBox item +void CommandDialog::set_buttons(int index) +{ + if (index < 0) + { + new_cmd(); + return; + } + /* + //bool sel = (lb->currentRow() >= 0); + Command *c ; + if(sel) + //c = commands[find_command(lb->currentText())]; + c = commands[find_command(lb->currentText())]; + else + c = commands[find_command(lb->text(index))]; + name->setText(c->name); + cmdline->setText(c->cmdline); + del->setEnabled(sel); + */ +} + +// called when clicked ! +void CommandDialog::set_select(const QModelIndex &index) +{ + Command *c = + static_cast(index.internalPointer()); // never Null ? + /* + if (item==NULL) return; // important + Command *c = commands[find_command(item->text())]; + */ + name->setText(c->name); + cmdline->setText(c->cmdline); + // DEL qcheck1->setChecked(c->toolbar); + // qcheck2->setChecked(c->popup); + + // bool sel = (listview->currentItem() >= 0); + if (c->name == "Update") + del->setEnabled(false); + else + del->setEnabled(true); +} + +void CommandDialog::reset() +{ + listview->reset(); + name->setText(""); + cmdline->setText(""); + add->setText("Add..."); + add->setEnabled(0); + button_ok->setEnabled(1); + listview->clearSelection(); +} + +void CommandDialog::new_cmd() +{ + reset(); + add->setEnabled(1); + name->setFocus(); +} + +void CommandDialog::add_new() +{ + if (name->text() == "") + return; + + // commands.add(new Command(name->text(), + // cmdline->text(),qcheck1->isChecked + // () )); + commands.append(new Command(name->text(), cmdline->text(), false)); + check_commandAll(); // TEMP + + listview->reset(); + add->setEnabled(0); + del->setEnabled(0); + button_ok->setEnabled(1); + + emit command_change(); // notice to refresh Qps::make_command_menu() + // control_bar->update_bar(); // ** important +} + +void CommandDialog::del_current() +{ + int idx = find_command(name->text()); + if (idx >= 0) + { + // printf("del\n"); + commands.removeAt(idx); + listview->reset(); // listview->reset(); + // control_bar->update_bar(); + emit command_change(); // notice to refresh menu_commands + } +} + diff --git a/src/commanddialog.h b/src/commanddialog.h new file mode 100644 index 0000000..e3e8c9e --- /dev/null +++ b/src/commanddialog.h @@ -0,0 +1,47 @@ +// commanddialog.h +// +// This program is free software. See the file COPYING for details. +// Author: Mattias Engdeg?rd, 1997-1999 + + +#ifndef COMMANDDIALOG_H +#define COMMANDDIALOG_H + +#include + +class QListView; +class QPushButton; +class QLineEdit; +class QCheckBox; +class QModelIndex; + +// class CommandDialog : public QWidget +class CommandDialog : public QDialog +{ + Q_OBJECT + public: + CommandDialog(); + +signals: + void command_change(); + + protected slots: + void new_cmd(); + void add_new(); + void del_current(); + void set_buttons(int); + void reset(); + void set_select(const QModelIndex &); + void event_name_midified(const QString &new_name); + void event_cmd_modified(); + void event_toolbar_checked(bool); + + private: + QListView *listview; + QPushButton *new0, *add, *del, *edit, *button_ok; + QLineEdit *name, *cmdline; + QCheckBox *qcheck1; + QCheckBox *qcheck2; +}; + +#endif // COMMANDDIALOG_H diff --git a/src/commandmodel.cpp b/src/commandmodel.cpp new file mode 100644 index 0000000..0fed974 --- /dev/null +++ b/src/commandmodel.cpp @@ -0,0 +1,47 @@ +// commandmodel.cpp +// +// This program is free software. See the file COPYING for details. +// Author: Mattias Engdeg?rd, 1997-1999 + +#include "commandmodel.h" + +#include "command.h" + +extern QList commands; + +CommandModel::CommandModel(QObject *parent) {} +CommandModel::~CommandModel() {} + +QModelIndex CommandModel::index(int row, int column, + const QModelIndex &parent) const +{ + if (row >= 0 and column >= 0 and row < commands.size() and column < 1) + { + Command *cmd = commands[row]; + return createIndex(row, column, cmd); + } + else + return QModelIndex(); +} +QModelIndex CommandModel::parent(const QModelIndex &child) const +{ + return QModelIndex(); +} +int CommandModel::rowCount(const QModelIndex &parent) const +{ + return commands.size(); +} +// int CommandModel::columnCount(const QModelIndex &parent) const{return 1;}; +QVariant CommandModel::data(const QModelIndex &index, int role) const +{ + if (role == Qt::DisplayRole) + { + Command *cmd = static_cast(index.internalPointer()); + return cmd->name; + } + if (role == Qt::DecorationRole) + { + } + return QVariant(); +} +void CommandModel::update() {} // TEMP diff --git a/src/commandmodel.h b/src/commandmodel.h new file mode 100644 index 0000000..64fd598 --- /dev/null +++ b/src/commandmodel.h @@ -0,0 +1,21 @@ +// commandmodel.h emacs, this is written in -*-c++-*- +// +// This program is free software. See the file COPYING for details. +// Author: Mattias EngdegÃ¥rd, 1997-1999 + +#include + +class CommandModel : public QAbstractItemModel +{ + Q_OBJECT + public: + CommandModel(QObject *parent = 0); + ~CommandModel(); + QModelIndex index(int row, int column, const QModelIndex &parent) const; + QModelIndex parent(const QModelIndex &child) const; + int rowCount(const QModelIndex &parent) const; + int columnCount(const QModelIndex &parent) const { return 1; }; + QVariant data(const QModelIndex &index, int role) const; + // Qt::ItemFlags flags(const QModelIndex &index) const; + void update(); // TEMP +}; diff --git a/src/commandutils.cpp b/src/commandutils.cpp new file mode 100644 index 0000000..4525264 --- /dev/null +++ b/src/commandutils.cpp @@ -0,0 +1,76 @@ +// commandutils.cpp +// +// This program is free software. See the file COPYING for details. +// Author: Mattias Engdeg?rd, 1997-1999 + +#include "commandutils.h" + +#include + +extern QList commands; + +int find_command(QString s) +{ + for (int i = 0; i < commands.size(); i++) + if (s == commands[i]->name) + return i; + return -1; +} + +// DEL has "&" end of the string ? +bool hasAmpersand(QString cmdline) +{ + QString str; + int len; + str = cmdline.simplified(); + + if (str == "%update") + return true; // internal command + + len = str.length(); + if (str[len - 1] == '&') + return true; + else + return false; +} + +void check_command(int idx) {} + +// +void check_commandAll() +{ + int i, idx; + + return; + for (int i = 0; i < commands.size(); i++) + { + if (hasAmpersand(commands[i]->cmdline) == false) + commands[i]->cmdline.append("&"); + } +} + +// after read ~/.qpsrc +void add_default_command() +{ + + int idx; + + /* + idx=find_command("Update"); + if (idx>=0) + commands[idx]->cmdline="%update"; + else + commands.add(new Command("Update","%update",true)); + */ + + /* + * PAUSED + idx=find_command("Quit"); + if (idx>=0) + commands[idx]->cmdline="killall qps"; + else commands.add(new Command("Quit","killall qps",false)); + */ + + // check_commandAll(); DEL? +} + diff --git a/src/commandutils.h b/src/commandutils.h new file mode 100644 index 0000000..5249069 --- /dev/null +++ b/src/commandutils.h @@ -0,0 +1,17 @@ +// commandutils.h +// +// This program is free software. See the file COPYING for details. +// Author: Mattias Engdeg?rd, 1997-1999 + +#ifndef COMMANDUTILS_H +#define COMMANDUTILS_H + +#include + +int find_command(QString s); +bool hasAmpersand(QString cmdline); +void check_command(int idx); +void check_commandAll(); +void add_default_command(); + +#endif // COMMANDUTILS_H diff --git a/src/details.h b/src/details.h index ed4eab6..28d1ae8 100644 --- a/src/details.h +++ b/src/details.h @@ -17,6 +17,7 @@ #include "proc.h" #include "lookup.h" +#include "tablefield.h" class Details : public QWidget { @@ -45,15 +46,6 @@ signals: Proc *pr; }; -struct TableField -{ - const char *name; - int width; - int gap; - int align; - const char *tooltip; -}; - // SimpleTable: a HeadedTable with fixed number of columns #include "htable.h" class SimpleTable : public HeadedTable diff --git a/src/execwindow.cpp b/src/execwindow.cpp new file mode 100644 index 0000000..90707ac --- /dev/null +++ b/src/execwindow.cpp @@ -0,0 +1,112 @@ +// execwindow.cpp +// +// This program is free software. See the file COPYING for details. +// Author: Mattias Engdeg?rd, 1997-1999 + +#include "execwindow.h" + +#include "watchcond.h" + +QList execlist; + +// ExecWindow +ExecWindow::ExecWindow() +{ + setupUi(this); + // connect(okButton, SIGNAL(clicked()), this, SLOT(close())); + // show(); +} + +ExecWindow::~ExecWindow() {} + +// eventcat_id; +ExecWindow::ExecWindow(watchCond *wc, int pid, QString cmd) +{ + setupUi(this); + setWindowTitle("Qps Watchdog"); + + wcond = wc; + + QString str; + + if (wc->cond == WATCH_PROCESS_START) + { + textEdit->append(cmd + "(" + QString::number(pid) + ")" + " start"); + } + if (wc->cond == WATCH_PROCESS_FINISH) + textEdit->append(cmd + "(" + QString::number(pid) + ")" + " finished"); + + flag_started = false; + + pr = new QProcess; // leak? + if (!wc->command.isEmpty()) // conflict pid's command + { + pr->start(wc->command); // thread run, if null then segfault occurs. ? + } + + connect(okButton, SIGNAL(clicked()), this, SLOT(cmd_ok())); + + connect(pr, SIGNAL(started()), this, SLOT(cmd_started())); + connect(pr, SIGNAL(finished(int, QProcess::ExitStatus)), this, + SLOT(cmd_finished(int, QProcess::ExitStatus))); + connect(pr, SIGNAL(error(QProcess::ProcessError)), this, + SLOT(cmd_error(QProcess::ProcessError))); + + show(); + + execlist.append(this); +} + +ExecWindow::ExecWindow(QString str, QString exec_cmd, int pid, QString cmd) +{ + setupUi(this); + // +} + +// QProcess: Destroyed while process is still running.(Segmentation fault) +void ExecWindow::cmd_ok() +{ + if (pr->state() == QProcess::Running) + { + // pr->kill(); + pr->terminate(); + return; + } + close(); // Qt::WA_DeleteOnClose +} + +// slot : catch terminate signal. +void ExecWindow::cmd_finished(int exitCode, QProcess::ExitStatus exitStatus) +{ + textEdit->append(wcond->command + " exit with code " + + QString::number(exitStatus)); + okButton->setText("Close"); + delete pr; +} + +void ExecWindow::cmd_started() +{ + textEdit->append(wcond->command + " [running]"); + okButton->setText("terminate command"); + flag_started = true; +} + +void ExecWindow::cmd_error(QProcess::ProcessError e) +{ + // not found command + // Error ? : + if (e == QProcess::FailedToStart) + // textEdit->append("Error : command not found [" + + // command + "]" + "(code + //" + QString::number(e) + ")" ); + textEdit->append("Error " + QString::number(e) + " : [" + + wcond->command + "] Maybe command not found"); + delete pr; +} + +void ExecWindow::setText(QString str) +{ + textEdit->append(str); + // label->setText(str); +} + diff --git a/src/execwindow.h b/src/execwindow.h new file mode 100644 index 0000000..f081e27 --- /dev/null +++ b/src/execwindow.h @@ -0,0 +1,37 @@ +// execwindow.h +// +// This program is free software. See the file COPYING for details. +// Author: Mattias Engdeg?rd, 1997-1999 + +#ifndef EXECWINDOW_H +#define EXECWINDOW_H + +#include +#include + +#include "ui_message.h" + +class watchCond; + +class ExecWindow : public QWidget, private Ui_ExecWindow +{ + Q_OBJECT + public: + ExecWindow(); + ExecWindow(QString str, QString exec_cmd, int pid = 0, QString cmd = ""); + ExecWindow(watchCond *wc, int pid = 0, QString cmd = ""); + ~ExecWindow(); + void setText(QString str); + QProcess *pr; + // QProcess proc; + QString execmd; + int flag_started; + watchCond *wcond; + protected slots: + void cmd_started(); + void cmd_finished(int exitCode, QProcess::ExitStatus exitStatus); + void cmd_error(QProcess::ProcessError error); + void cmd_ok(); +}; + +#endif // EXECWINDOW_H diff --git a/src/listmodel.cpp b/src/listmodel.cpp new file mode 100644 index 0000000..87119e8 --- /dev/null +++ b/src/listmodel.cpp @@ -0,0 +1,107 @@ +// listmodel.cpp +// +// This program is free software. See the file COPYING for details. +// Author: Mattias Engdeg?rd, 1997-1999 + +#include "listmodel.h" + +#include "watchcond.h" + +extern QList watchlist; + +QModelIndex ListModel::index(int row, int column, + const QModelIndex &parent) const +{ + // printf("index %d %d\n",row,column); + if (row >= 0 and column >= 0 and row < watchlist.size()) + { + if (column < 2) + { + watchCond *item = watchlist[row]; + return createIndex(row, column, item); + } + } + return QModelIndex(); +} + +void ListModel::update(int row) +{ + emit dataChanged(index(row, 0), index(row, 1)); +} + +void ListModel::update(const QModelIndex &idx) { emit dataChanged(idx, idx); } + +// Pure Virtual +QModelIndex ListModel::parent(const QModelIndex &child) const +{ + return QModelIndex(); // no parent! +} +int ListModel::rowCount(const QModelIndex &parent) const +{ + return watchlist.size(); +} +QVariant ListModel::headerData(int section, Qt::Orientation orientation, + int role) const +{ + // printf("headerData\n"); + if (role == Qt::DisplayRole) + { + if (section == 0) + return QString("Event Category"); + if (section == 1) + return QString("Enable"); + } + /* + if (role == Qt::FontRole) + { + QFont f=QFont(); + f.setBold(false); + return f; + } */ + if (role == Qt::SizeHintRole) + { + // return QSize(18,18); + } + return QVariant(); +} + +QVariant ListModel::data(const QModelIndex &index, int role) const +{ + // printf("data\n"); + watchCond *item = static_cast(index.internalPointer()); + if (index.column() == 0) + { + if (role == Qt::DisplayRole) + { + return QString(item->getstring()); + } + if (role == Qt::DecorationRole) + { + } + if (role == Qt::EditRole) + { + } + } + + if (index.column() == 1) + { + if (role == Qt::CheckStateRole) + { + if (item->enable) + return Qt::Checked; + else + return Qt::Unchecked; + } + if (role == Qt::TextAlignmentRole) + return Qt::AlignRight; + if (role == Qt::EditRole) + { + } + } + if (role == Qt::SizeHintRole) + { + // return QSize(18,18); + } + return QVariant(); +} + diff --git a/src/listmodel.h b/src/listmodel.h new file mode 100644 index 0000000..9f76e49 --- /dev/null +++ b/src/listmodel.h @@ -0,0 +1,36 @@ +// listmodel.h +// +// This program is free software. See the file COPYING for details. +// Author: Mattias Engdeg?rd, 1997-1999 + +#ifndef LISTMODEL_H +#define LISTMODEL_H + +#include +// class ListModel : public QAbstractItemModel +class ListModel : public QAbstractTableModel +// class ListModel : public QStandardItemModel +{ + Q_OBJECT + public: + ListModel(QObject *parent = 0){}; + ~ListModel(){}; + QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const; // pure + QModelIndex parent(const QModelIndex &child) const; // pure virtual + int rowCount(const QModelIndex &parent) const; + int columnCount(const QModelIndex &parent) const { return 2; }; + QVariant data(const QModelIndex &index, int role) const; + QVariant headerData(int section, Qt::Orientation o, int role) const; + // QMap itemData ( const QModelIndex & index ) const + //; + void update() + { // reset(); + } + void update(const QModelIndex &idx); + void update(int row); + // Qt::ItemFlags flags(const QModelIndex &index) const; + // void update(); //TEMP +}; + +#endif // LISTMODEL_H diff --git a/src/misc.cpp b/src/misc.cpp index 2c2ee94..e0a1553 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -1211,5 +1211,3 @@ void QTabWidgetX::showTab(bool flag) // setDocumentMode (true); // QT 4.5 #endif } - -#include "qticonloader.cpp" diff --git a/src/misc.h b/src/misc.h index 2da8a8b..a3ba99e 100644 --- a/src/misc.h +++ b/src/misc.h @@ -29,8 +29,6 @@ #include #endif -#include "qticonloader.h" - char *userName(int uid, int euid); char *groupName(int gid, int egid); diff --git a/src/qps.cpp b/src/qps.cpp index ea66c41..2d07b46 100644 --- a/src/qps.cpp +++ b/src/qps.cpp @@ -41,7 +41,12 @@ #include //for sleep #include "qps.h" +#include "qpsapp.h" #include "dialogs.h" +#include "commanddialog.h" +#include "commandutils.h" +#include "watchcond.h" +#include "watchdogdialog.h" #include "lookup.h" #include "misc.h" @@ -196,9 +201,7 @@ Qps::Qps() #endif m_field->addSeparator(); - // act=m_field->addAction(QtIconLoader::icon("edit-find-replace"),"Save - // Current as Custom Fields",this, SLOT(menu_custom())); - act = m_field->addAction(QtIconLoader::icon("edit-find-replace"), + act = m_field->addAction(QIcon::fromTheme(QStringLiteral("edit-find-replace")), "Select Custom Fields...", this, SLOT(menu_custom())); act->setData(MENU_CUSTOM); @@ -229,10 +232,7 @@ Qps::Qps() act->setData(QVariant(MENU_CUMUL)); m_options->addSeparator(); - // m_options->addAction(QtIconLoader::icon("gtk-preferences" /* - // gnome-settings - // */),"Preferences...", this, SLOT(menu_prefs())); //MENU_PREFS - m_options->addAction(QIcon(":icon/preferences-system.png"), + m_options->addAction(QIcon::fromTheme(QStringLiteral("preferences-system")), "Preferences...", this, SLOT(menu_prefs())); // MENU_PREFS @@ -240,8 +240,7 @@ Qps::Qps() QMenu *m_help = new QMenu("Help", this); // m_help->addAction("FAQ", this, SLOT(license())); - // m_help->addAction("About", this, SLOT(about())); //gtk-help,help - m_help->addAction(QtIconLoader::icon("help-about"), "Feedback", this, + m_help->addAction(QIcon::fromTheme("help-about"), "Feedback", this, SLOT(about())); // menu = new QMenuBar(this); @@ -1187,10 +1186,7 @@ void Qps::make_command_menu() //#ifdef SOLARIS /* Solaris CDE don't have a tray, so we need a method to terminate */ m_command->addSeparator(); - // m_command->addAction(QtIconLoader::icon("application-exit"), "&Quit", - // this, - // SLOT(save_quit()), Qt::ALT + Qt::Key_Q); - m_command->addAction(QtIconLoader::icon("gtk-quit"), "&Quit", this, + m_command->addAction(QIcon::fromTheme(QStringLiteral("application-exit")), "&Quit", this, SLOT(save_quit()), Qt::ALT + Qt::Key_Q); //#endif } @@ -2145,80 +2141,6 @@ void Qps::hideEvent(QHideEvent *event) // geo=saveGeometry(); } -// MOD!!!: For systray update. -// this trick very suck, but I can't find a better solution. -class QpsApp : public QApplication -{ - public: - QpsApp(int &argc, char **argv) : QApplication(argc, argv){}; - void commitData(QSessionManager &sm); - void saveState(QSessionManager &manager); - - /* - virtual bool x11EventFilter ( XEvent *xev ){ - // catch X11 event for systray_update !! which event? - ///if(trayicon!=NULL) return - trayicon->checkNewTrayEvent(xev); - return false; // events to qt. - }; */ -}; - -#include -void QpsApp::saveState(QSessionManager &manager) -{ - // printf("saveState()\n"); - // manager.setRestartHint(QSessionManager::RestartIfRunning); - // manager.release(); -} - -// this is called when X Logout -// closeEvent() never called !!! -void QpsApp::commitData(QSessionManager &manager) -{ - /* - printf("commitData()\n"); - manager.setRestartHint(QSessionManager::RestartIfRunning); - qps->flag_exit=true; // ready to Logout - qps->save_settings() ; - manager.release(); - sleep(2); - return; - if (manager.allowsInteraction()) { - int ret = QMessageBox::warning( - qps, - tr("My Application"), - tr("Save changes to document?"), - QMessageBox::Save | QMessageBox::Discard | - QMessageBox::Cancel); - - switch (ret) { - case QMessageBox::Save: - manager.release(); - // if (!saveDocument()) manager.cancel(); - break; - case QMessageBox::Discard: - break; - case QMessageBox::Cancel: - default: - manager.cancel(); - } - } else { - - manager.release(); - - // we did not get permission to interact, then - // do something reasonable instead - } - */ - /* - //DEL sm.release(); - qDebug("Qps: Session saved\n"); - // sm.cancel(); - //sm.setRestartHint (QSessionManager::RestartIfRunning); - QApplication::commitData(sm); - */ -} - #include void signal_handler(int sig) { diff --git a/src/qps.h b/src/qps.h index fa13d3f..91f1c7d 100644 --- a/src/qps.h +++ b/src/qps.h @@ -43,6 +43,9 @@ #define FUNC_END #include + +class CommandDialog; + class Qps : public QWidget { Q_OBJECT diff --git a/src/qpsapp.cpp b/src/qpsapp.cpp new file mode 100644 index 0000000..7118bb8 --- /dev/null +++ b/src/qpsapp.cpp @@ -0,0 +1,61 @@ +// This program is free software. See the file COPYING for details. +// Author: Mattias Engdeg?rd, 1997-1999 +// fasthyun@magicn.com 2005-2012 +// daehyun.yang@gmail.com 2015- + +#include "qpsapp.h" + +void QpsApp::saveState(QSessionManager &manager) +{ + // printf("saveState()\n"); + // manager.setRestartHint(QSessionManager::RestartIfRunning); + // manager.release(); +} + +// this is called when X Logout +// closeEvent() never called !! +void QpsApp::commitData(QSessionManager &manager) +{ + /* + printf("commitData()\n"); + manager.setRestartHint(QSessionManager::RestartIfRunning); + qps->flag_exit=true; // ready to Logout + qps->save_settings() ; + manager.release(); + sleep(2); + return; + if (manager.allowsInteraction()) { + int ret = QMessageBox::warning( + qps, + tr("My Application"), + tr("Save changes to document?"), + QMessageBox::Save | QMessageBox::Discard | + QMessageBox::Cancel); + + switch (ret) { + case QMessageBox::Save: + manager.release(); + // if (!saveDocument()) manager.cancel(); + break; + case QMessageBox::Discard: + break; + case QMessageBox::Cancel: + default: + manager.cancel(); + } + } else { + + manager.release(); + + // we did not get permission to interact, then + // do something reasonable instead + } + */ + /* + //DEL sm.release(); + qDebug("Qps: Session saved\n"); + // sm.cancel(); + //sm.setRestartHint (QSessionManager::RestartIfRunning); + QApplication::commitData(sm); + */ +} diff --git a/src/qpsapp.h b/src/qpsapp.h new file mode 100644 index 0000000..2ed536c --- /dev/null +++ b/src/qpsapp.h @@ -0,0 +1,29 @@ +// This program is free software. See the file COPYING for details. +// Author: Mattias Engdeg?rd, 1997-1999 +// fasthyun@magicn.com 2005-2012 +// daehyun.yang@gmail.com 2015- + +#ifndef QPSAPP_H +#define QPSAPP_H + +#include + +// MOD!!!: For systray update. +// this trick very suck, but I can't find a better solution. +class QpsApp : public QApplication +{ + public: + QpsApp(int &argc, char **argv) : QApplication(argc, argv){}; + void commitData(QSessionManager &sm); + void saveState(QSessionManager &manager); + + /* + virtual bool x11EventFilter ( XEvent *xev ){ + // catch X11 event for systray_update !! which event? + ///if(trayicon!=NULL) return + trayicon->checkNewTrayEvent(xev); + return false; // events to qt. + }; */ +}; + +#endif // QPSAPP_H diff --git a/src/qticonloader.cpp b/src/qticonloader.cpp deleted file mode 100644 index 743b7e2..0000000 --- a/src/qticonloader.cpp +++ /dev/null @@ -1,389 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -#include "qticonloader.h" -#include - -#include -#include -#include -#include -#include -#include -#include - -#ifdef Q_WS_X11 - -class QIconTheme -{ - public: - QIconTheme(QHash dirList, QStringList parents) - : _dirList(dirList), _parents(parents), _valid(true) - { - } - QIconTheme() : _valid(false) {} - QHash dirList() { return _dirList; } - QStringList parents() { return _parents; } - bool isValid() { return _valid; } - - private: - QHash _dirList; - QStringList _parents; - bool _valid; -}; - -class QtIconLoaderImplementation -{ - public: - QtIconLoaderImplementation(); - QPixmap findIcon(int size, const QString &name) const; - - private: - QIconTheme parseIndexFile(const QString &themeName) const; - void lookupIconTheme() const; - QPixmap findIconHelper(int size, const QString &themeName, - const QString &iconName, QStringList &visited) const; - mutable QString themeName; - mutable QStringList iconDirs; - mutable QHash themeList; -}; - -Q_GLOBAL_STATIC(QtIconLoaderImplementation, iconLoaderInstance) -#endif - -/*! - - Returns the standard icon for the given icon /a name - as specified in the freedesktop icon spec - http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html - - /a fallback is an optional argument to specify the icon to be used if - no icon is found on the platform. This is particularily useful for - crossplatform code. - -*/ -QIcon QtIconLoader::icon(const QString &name, const QIcon &fallback) -{ - QIcon icon; -#ifdef Q_WS_X11 - QString pngExtension(QLatin1String(".png")); - QList iconSizes; - iconSizes << 16 << 24 << 32 << 48 << 64; - Q_FOREACH (int size, iconSizes) - { - icon.addPixmap( - iconLoaderInstance()->findIcon(size, name + pngExtension)); - // icon.addPixmap(iconLoaderInstance()->findIcon(size, - // name)); - } -#endif - if (icon.isNull()) - icon = fallback; - Q_UNUSED(name); - return icon; -} - -#ifdef Q_WS_X11 - -QtIconLoaderImplementation::QtIconLoaderImplementation() { lookupIconTheme(); } - -extern "C" { -struct GConfClient; -struct GError; -typedef void (*Ptr_g_type_init)(); -typedef GConfClient *(*Ptr_gconf_client_get_default)(); -typedef char *(*Ptr_gconf_client_get_string)(GConfClient *, const char *, - GError **); -typedef void (*Ptr_g_object_unref)(void *); -typedef void (*Ptr_g_error_free)(GError *); -typedef void (*Ptr_g_free)(void *); -static Ptr_g_type_init p_g_type_init = 0; -static Ptr_gconf_client_get_default p_gconf_client_get_default = 0; -static Ptr_gconf_client_get_string p_gconf_client_get_string = 0; -static Ptr_g_object_unref p_g_object_unref = 0; -static Ptr_g_error_free p_g_error_free = 0; -static Ptr_g_free p_g_free = 0; -} - -static int kdeVersion() -{ - static int version = qgetenv("KDE_SESSION_VERSION").toInt(); - return version; -} - -static QString kdeHome() -{ - static QString kdeHomePath; - if (kdeHomePath.isEmpty()) - { - kdeHomePath = QFile::decodeName(qgetenv("KDEHOME")); - if (kdeHomePath.isEmpty()) - { - int kdeSessionVersion = kdeVersion(); - QDir homeDir(QDir::homePath()); - QString kdeConfDir(QLatin1String("/.kde")); - if (4 == kdeSessionVersion && - homeDir.exists(QLatin1String(".kde4"))) - kdeConfDir = QLatin1String("/.kde4"); - kdeHomePath = QDir::homePath() + kdeConfDir; - } - } - return kdeHomePath; -} - -void QtIconLoaderImplementation::lookupIconTheme() const -{ - -#ifdef Q_WS_X11 - QString dataDirs = QFile::decodeName(getenv("XDG_DATA_DIRS")); - if (dataDirs.isEmpty()) - dataDirs = QLatin1String("/usr/local/share/:/usr/share/"); - - dataDirs.prepend(QDir::homePath() + QLatin1String("/:")); - iconDirs = dataDirs.split(QLatin1Char(':')); - - // If we are running GNOME we resolve and use GConf. In all other - // cases we currently use the KDE icon theme - - if (qgetenv("DESKTOP_SESSION") == "gnome" || - !qgetenv("GNOME_DESKTOP_SESSION_ID").isEmpty()) - { - - if (themeName.isEmpty()) - { - // Resolve glib and gconf - - p_g_type_init = (Ptr_g_type_init)QLibrary::resolve( - QLatin1String("gobject-2.0"), 0, "g_type_init"); - p_gconf_client_get_default = - (Ptr_gconf_client_get_default)QLibrary::resolve( - QLatin1String("gconf-2"), 4, "gconf_client_get_default"); - p_gconf_client_get_string = - (Ptr_gconf_client_get_string)QLibrary::resolve( - QLatin1String("gconf-2"), 4, "gconf_client_get_string"); - p_g_object_unref = (Ptr_g_object_unref)QLibrary::resolve( - QLatin1String("gobject-2.0"), 0, "g_object_unref"); - p_g_error_free = (Ptr_g_error_free)QLibrary::resolve( - QLatin1String("glib-2.0"), 0, "g_error_free"); - p_g_free = (Ptr_g_free)QLibrary::resolve(QLatin1String("glib-2.0"), - 0, "g_free"); - - if (p_g_type_init && p_gconf_client_get_default && - p_gconf_client_get_string && p_g_object_unref && - p_g_error_free && p_g_free) - { - - p_g_type_init(); - GConfClient *client = p_gconf_client_get_default(); - GError *err = 0; - - char *str = p_gconf_client_get_string( - client, "/desktop/gnome/interface/icon_theme", &err); - if (!err) - { - themeName = QString::fromUtf8(str); - p_g_free(str); - } - - p_g_object_unref(client); - if (err) - p_g_error_free(err); - } - if (themeName.isEmpty()) - themeName = QLatin1String("gnome"); - } - - if (!themeName.isEmpty()) - return; - } - - // KDE (and others) - if (dataDirs.isEmpty()) - dataDirs = QLatin1String("/usr/local/share/:/usr/share/"); - - dataDirs += QLatin1Char(':') + kdeHome() + QLatin1String("/share"); - dataDirs.prepend(QDir::homePath() + QLatin1String("/:")); - QStringList kdeDirs = - QFile::decodeName(getenv("KDEDIRS")).split(QLatin1Char(':')); - Q_FOREACH (const QString dirName, kdeDirs) - dataDirs.append(QLatin1Char(':') + dirName + QLatin1String("/share")); - iconDirs = dataDirs.split(QLatin1Char(':')); - - QFileInfo fileInfo(QLatin1String("/usr/share/icons/default.kde")); - QDir dir(fileInfo.canonicalFilePath()); - QString kdeDefault = kdeVersion() >= 4 ? QString::fromLatin1("oxygen") - : QString::fromLatin1("crystalsvg"); - QString defaultTheme = fileInfo.exists() ? dir.dirName() : kdeDefault; - QSettings settings(kdeHome() + QLatin1String("/share/config/kdeglobals"), - QSettings::IniFormat); - settings.beginGroup(QLatin1String("Icons")); - themeName = settings.value(QLatin1String("Theme"), defaultTheme).toString(); -#endif -} - -QIconTheme -QtIconLoaderImplementation::parseIndexFile(const QString &themeName) const -{ - QIconTheme theme; - QFile themeIndex; - QStringList parents; - QHash dirList; - - for (int i = 0; i < iconDirs.size() && !themeIndex.exists(); ++i) - { - const QString &contentDir = QLatin1String( - iconDirs[i].startsWith(QDir::homePath()) ? "/.icons/" : "/icons/"); - themeIndex.setFileName(iconDirs[i] + contentDir + themeName + - QLatin1String("/index.theme")); - } - - if (themeIndex.exists()) - { - QSettings indexReader(themeIndex.fileName(), QSettings::IniFormat); - Q_FOREACH (const QString &key, indexReader.allKeys()) - { - if (key.endsWith("/Size")) - { - if (int size = indexReader.value(key).toInt()) - dirList.insertMulti(size, key.left(key.size() - 5)); - } - } - - // Parent themes provide fallbacks for missing icons - parents = indexReader.value(QLatin1String("Icon Theme/Inherits")) - .toStringList(); - } - - if (kdeVersion() >= 3) - { - QFileInfo fileInfo(QLatin1String("/usr/share/icons/default.kde")); - QDir dir(fileInfo.canonicalFilePath()); - QString defaultKDETheme = - dir.exists() ? dir.dirName() - : kdeVersion() == 3 ? QString::fromLatin1("crystalsvg") - : QString::fromLatin1("oxygen"); - if (!parents.contains(defaultKDETheme) && themeName != defaultKDETheme) - parents.append(defaultKDETheme); - } - else if (parents.isEmpty() && themeName != QLatin1String("hicolor")) - { - parents.append(QLatin1String("hicolor")); - } - - theme = QIconTheme(dirList, parents); - return theme; -} - -QPixmap QtIconLoaderImplementation::findIconHelper(int size, - const QString &themeName, - const QString &iconName, - QStringList &visited) const -{ - QPixmap pixmap; - - if (!themeName.isEmpty()) - { - visited << themeName; - QIconTheme theme = themeList.value(themeName); - - if (!theme.isValid()) - { - theme = parseIndexFile(themeName); - themeList.insert(themeName, theme); - } - - if (!theme.isValid()) - return QPixmap(); - - QList subDirs = theme.dirList().values(size); - - for (int i = 0; i < iconDirs.size(); ++i) - { - for (int j = 0; j < subDirs.size(); ++j) - { - QString contentDir = (iconDirs[i].startsWith(QDir::homePath())) - ? QLatin1String("/.icons/") - : QLatin1String("/icons/"); - QString fileName = iconDirs[i] + contentDir + themeName + - QLatin1Char('/') + subDirs[j] + - QLatin1Char('/') + iconName; - QFile file(fileName); - if (file.exists()) - pixmap.load(fileName); - if (!pixmap.isNull()) - break; - } - } - - if (pixmap.isNull()) - { - QStringList parents = theme.parents(); - // search recursively through inherited themes - for (int i = 0; pixmap.isNull() && i < parents.size(); ++i) - { - QString parentTheme = parents[i].trimmed(); - if (!visited.contains(parentTheme)) // guard - // against - // endless - // recursion - pixmap = - findIconHelper(size, parentTheme, iconName, visited); - } - } - } - return pixmap; -} - -QPixmap QtIconLoaderImplementation::findIcon(int size, - const QString &name) const -{ - QPixmap pixmap; - QString pixmapName = QLatin1String("$qt") + name + QString::number(size); - if (QPixmapCache::find(pixmapName, pixmap)) - return pixmap; - - if (!themeName.isEmpty()) - { - QStringList visited; - pixmap = findIconHelper(size, themeName, name, visited); - } - QPixmapCache::insert(pixmapName, pixmap); - return pixmap; -} -#endif // Q_WS_X11 diff --git a/src/qticonloader.h b/src/qticonloader.h deleted file mode 100644 index aba2449..0000000 --- a/src/qticonloader.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -#ifndef QTICONLOADER_H -#define QTICONLOADER_H - -#include - -// This is the QtIconLoader -// Version 0.1 -// - -class QtIconLoader -{ - public: - static QIcon icon(const QString &name, const QIcon &fallback = QIcon()); -}; - -#endif // QTICONLOADER_H diff --git a/src/tablefield.h b/src/tablefield.h new file mode 100644 index 0000000..c8c4f18 --- /dev/null +++ b/src/tablefield.h @@ -0,0 +1,18 @@ +// tablefield.h emacs, this is written in -*-c++-*- +// +// This program is free software. See the file COPYING for details. +// Author: Mattias EngdegÃ¥rd, 1997-1999 + +#ifndef TABLEFIELD_H +#define TABLEFIELD_H + +struct TableField +{ + const char *name; + int width; + int gap; + int align; + const char *tooltip; +}; + +#endif // TABLEFIELD_H diff --git a/src/watchcond.cpp b/src/watchcond.cpp new file mode 100644 index 0000000..9fd5623 --- /dev/null +++ b/src/watchcond.cpp @@ -0,0 +1,76 @@ +// watchcond.cpp +// +// This program is free software. See the file COPYING for details. +// Author: Mattias Engdeg?rd, 1997-1999 + +#include "watchcond.h" + +QString watchCond::getVal(QString &str, const char *key) +{ + int n; // key.length(); + int idx = str.indexOf(key); + if (idx < 0) + return "cant' found"; + + idx = str.indexOf("[", idx); + if (idx < 0) + return "[ error"; + int idx_end = str.indexOf("]", idx); + if (idx_end < 0) + return "] error"; + n = idx_end - idx; + return str.mid(idx + 1, n - 1); +} +QString watchCond::getstring() +{ + QString string; + string.clear(); + switch (cond) + { + case WATCH_PROCESS_FINISH: + string.append("if process [" + procname + "] finish, "); + // string=string.sprintf("if process [%s] finish",procname); + break; + case WATCH_PROCESS_START: + string.append("if process [" + procname + "] start, "); + break; + case WATCH_SYS_CPU_OVER: + string.append("if sys_cpu over [" + QString::number(cpu) + "], "); + break; + case WATCH_SYS_CPU_UNDER: + string.append("if sys_cpu under [" + QString::number(cpu) + "], "); + break; + default: + ; + } + if (!command.isEmpty()) + string.append("exec [" + command + "] "); + if (!message.isEmpty()) + string.append("showmsg [" + message + "] "); + if (enable) + string.append("enabled"); + else + string.append("disabled"); + + return string; +} +void watchCond::putstring(QString str) +{ + if (str.contains("if process")) + { + if (str.contains("start")) + cond = WATCH_PROCESS_START; + if (str.contains("finish")) + cond = WATCH_PROCESS_FINISH; + procname = getVal(str, "if process"); + } + if (str.contains("exec")) + command = getVal(str, "exec"); + if (str.contains("showmsg")) + message = getVal(str, "showmsg"); + if (str.contains("enabled")) + enable = true; + else + enable = false; +} + diff --git a/src/watchcond.h b/src/watchcond.h new file mode 100644 index 0000000..d4d02c0 --- /dev/null +++ b/src/watchcond.h @@ -0,0 +1,50 @@ +// watchcond.h +// +// This program is free software. See the file COPYING for details. +// Author: Mattias Engdeg?rd, 1997-1999 + +#ifndef WATCHCOND_H +#define WATCHCOND_H + +#include + +#define WATCH_PROCESS_START 0 +#define WATCH_PROCESS_FINISH 1 +#define WATCH_PROCESS_CPU_OVER 2 +#define WATCH_SYS_CPU_OVER 3 +#define WATCH_SYS_CPU_UNDER 4 + + +// if process [name] start, exec [command], showmsg [xxx] +// if process [name] finish exec [command], showmsg [xxx] +// if system cpu over [90%], exec [command], msg [xxx] +// if system cpu under [10%], exec [command], msg [xxx] +// if process [name] cpu over [90%] exec [command] msg [xxx] +// if process [name] start, kill_it, msg [xxx] +// if process [name] start, soundplay [ ], msg [xxx] + +class watchCond +{ + public: + int cond; + int enable; + int cpu; + QString procname; + QString command; + QString message; + + watchCond() + { + enable = 0; + // procname[0]=0; command[0]=0; + // message[0]=0; + } + // key [txt] [a] + // QString getVal(QString &str, QString &key) + QString getVal(QString &str, const char *key); + QString getstring(); + void putstring(QString str); +}; + +#endif // WATCHCOND_H + diff --git a/src/watchdogdialog.cpp b/src/watchdogdialog.cpp new file mode 100644 index 0000000..a47e548 --- /dev/null +++ b/src/watchdogdialog.cpp @@ -0,0 +1,239 @@ +// watchdialog.h +// +// This program is free software. See the file COPYING for details. +// Author: Mattias Engdeg?rd, 1997-1999 + +#include "watchdogdialog.h" + +#include "listmodel.h" +#include "checkboxdelegate.h" +#include "misc.h" // TBloon class +#include "qps.h" +#include "watchcond.h" + +#include + +extern QList watchlist; +extern Qps *qps; + +WatchdogDialog::WatchdogDialog() +{ + setupUi(this); + listmodel = new ListModel(); + + tableView->setModel(listmodel); + checkBoxDelegate delegate; + tableView->setEditTriggers(QAbstractItemView::SelectedClicked); + /// tableView->setItemDelegate(&delegate); + + tableView->setSelectionBehavior(QAbstractItemView::SelectRows); + tableView->setSelectionMode(QAbstractItemView::SingleSelection); + QHeaderView *h = tableView->verticalHeader(); + h->setVisible(false); + + QHeaderView *v = tableView->horizontalHeader(); +#if QT_VERSION >= 0x050000 + v->setSectionResizeMode(0, QHeaderView::Stretch); + v->setSectionResizeMode(1, QHeaderView::ResizeToContents); +#endif + // v->setClickable (false); + connect(newButton, SIGNAL(clicked()), this, SLOT(_new())); + connect(closeButton, SIGNAL(clicked()), this, SLOT(apply())); + connect(addButton, SIGNAL(clicked()), this, SLOT(add())); + connect(delButton, SIGNAL(clicked()), this, SLOT(del())); + connect(comboBox, SIGNAL(activated(int)), SLOT(comboChanged(int))); + connect(comboBox, SIGNAL(highlighted(const QString &)), + SLOT(condChanged(const QString &))); + + connect(tableView, SIGNAL(clicked(const QModelIndex &)), + SLOT(eventcat_slected(const QModelIndex &))); + connect(message, SIGNAL(textEdited(const QString &)), + SLOT(Changed(const QString &))); + connect(command, SIGNAL(textEdited(const QString &)), + SLOT(Changed(const QString &))); + connect(proc_name, SIGNAL(textEdited(const QString &)), + SLOT(Changed(const QString &))); + connect(comboBox, SIGNAL(activated(const QString &)), + SLOT(Changed(const QString &))); + + checkBox_alreadyrun->hide(); + listView->hide(); + spinBox->hide(); + label_cpu->hide(); + /// printf("close ...\n"); + // tableView->update(); + // listmodel->update(); // meaningless.. + + TBloon *bloon = new TBloon(this); + return; +} + +void WatchdogDialog::showEvent(QShowEvent *event) +{ + // Qt 4.4.0 bug? + // printf("show!!!!!!!!!\n"); + listmodel->update(); +} +void WatchdogDialog::comboChanged(int idx) +{ + + // itemText(idx); + QString str = comboBox->currentText(); + + if (str.contains("cpu")) + { + label_cpu->show(); + spinBox->show(); + } + else + { + spinBox->hide(); + label_cpu->hide(); + } + + if (str.contains("process")) + { + label_procname->show(); + proc_name->show(); + } + else + { + label_procname->hide(); + proc_name->hide(); + } + + if (message->text().isEmpty()) + { + // if(str.contains("start")) message->setText("%CMD start + // with pid %PID"); + // if(str.contains("finish")) message->setText("%CMD + // finish with pid + //%PID"); + } +} + +void WatchdogDialog::eventcat_slected(const QModelIndex &idx) +{ + + watchCond *w = watchlist[idx.row()]; + // printf("row=%d\n",at=idx.row()); + + if (idx.column() == 1) + { + w->enable = !(w->enable); + listmodel->update(idx.row()); + return; + } + + QString str = idx.data().toString(); // Qt::DisplayRol + + if (str.contains("process")) + proc_name->setText(w->procname); + else + proc_name->setText(""); + if (str.contains("cpu")) + spinBox->setSingleStep(w->cpu); + else + spinBox->setSingleStep(50); + if (str.contains("exec")) + command->setText(w->command); + else + command->setText(""); + if (str.contains("showmsg")) + message->setText(w->message); + else + message->setText(""); + + checkCombo(); + comboBox->setCurrentIndex(w->cond); +} + +void WatchdogDialog::Changed(const QString &str) +{ + QModelIndex idx = tableView->currentIndex(); + // QModelIndexList list=tableView->selectedIndexes (); + bool flag = tableView->selectionModel()->hasSelection(); + // if(list.count() and idx.isValid()) + if (flag and idx.isValid()) + { + int at = idx.row(); + watchCond *w = watchlist[at]; + w->message = message->text(); + w->command = command->text(); + w->procname = proc_name->text(); + w->cond = comboBox->currentIndex(); + listmodel->update(at); + // watchlist.removeAt(at); + } + // listmodel->update(); +} + +void WatchdogDialog::checkCombo() +{ + if (comboBox->count() == 1) + { + comboBox->clear(); + comboBox->addItem("if process start"); + comboBox->addItem("if process finish"); + return; + } +} + +// comboChanged() -> checkCombo() +void WatchdogDialog::condChanged(const QString &str) +{ + checkCombo(); + // what is this? + // printf("chagend\n"); + // comboBox->currentText(); + // command->text(); + // message->text(); +} + +void WatchdogDialog::_new() +{ + tableView->clearSelection(); + proc_name->clear(); + command->clear(); + message->clear(); + comboBox->clear(); + comboBox->addItem("select condition"); +} + +void WatchdogDialog::add() +{ + watchCond *w = new watchCond; + w->enable = true; + w->cond = comboBox->currentIndex(); + w->command = command->text(); + w->message = message->text(); + w->procname = proc_name->text(); + watchlist.append(w); + // listView->update(QModelIndex()); + // listView->reset(); + // tableView->reset(); + // listmodel->insertRow(listmodel->rowCount(QModelIndex())); + // tableView->update(QModelIndex()); + // tableView->dataChanged(QModelIndex(),QModelIndex()); //protected + listmodel->update(); +} + +void WatchdogDialog::del() +{ + // QModelIndex idx=listView->currentIndex(); + QModelIndex idx = tableView->currentIndex(); + if (idx.isValid()) + { + int at = idx.row(); + watchlist.removeAt(at); + } + listmodel->update(); + tableView->setCurrentIndex(idx); +} + +void WatchdogDialog::apply() +{ + qps->write_settings(); + close(); +} + diff --git a/src/watchdogdialog.h b/src/watchdogdialog.h new file mode 100644 index 0000000..50af4b8 --- /dev/null +++ b/src/watchdogdialog.h @@ -0,0 +1,48 @@ +// watchdogdialog.cpp +// +// This program is free software. See the file COPYING for details. +// Author: Mattias Engdeg?rd, 1997-1999 + +#ifndef WATCHDOGDIALOG_H +#define WATCHDOGDIALOG_H + +#include "ui_watchdog.h" + +#include +#include +#include + +class ListModel; +class QShowEvent; + +class WatchdogDialog : public QDialog, private Ui_EventDialog +{ + Q_OBJECT + public: + WatchdogDialog(); + ListModel *listmodel; + // signals: + // void command_change(); + void checkCombo(); + protected slots: + void _new(); + void apply(); + void add(); + void del(); + void condChanged(const QString &str); + void Changed(const QString &str); + + void comboChanged(int); + void eventcat_slected(const QModelIndex &idx); + + protected: + virtual void showEvent(QShowEvent *event); + + // void set_select( const QModelIndex & ); + // void event_name_midified(const QString &new_name); + // void event_cmd_modified(); + // void event_toolbar_checked(bool); + private: +}; + +#endif // WATCHDOGDIALOG_H