Skip to content

Commit 65d41e8

Browse files
author
jeroen
committedAug 24, 2017
*Some changes
1 parent 066313a commit 65d41e8

7 files changed

+88
-19
lines changed
 

‎src/gui/priority.cpp

+26-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
#include <KLocalizedString>
12
#include "priority.h"
23
#include <QString>
34
#include <sys/time.h>
45
#include <sys/resource.h>
6+
#include <QMessageBox>
57
#include "src/base/utils.h"
68
PriorityDialog::PriorityDialog(TProcessInfo* p_info)
79
{
@@ -11,23 +13,41 @@ PriorityDialog::PriorityDialog(TProcessInfo* p_info)
1113
ui.processName->setText(p_info->getComm());
1214
ui.priority->setText(QString::number(p_info->getPriority()));
1315
connect(ui.okButton,SIGNAL(clicked()),this,SLOT(pressOk()));
16+
connect(ui.cancelButton,SIGNAL(clicked()),this,SLOT(pressCancel()));
1417
}
1518

19+
void PriorityDialog::errorMessage(QString p_message)
20+
{
21+
QMessageBox l_mb(QMessageBox::Warning ,i18n("Error"),p_message,QMessageBox::Ok);
22+
l_mb.exec();
23+
}
24+
25+
1626
void PriorityDialog::pressCancel()
1727
{
28+
close();
1829
}
1930

31+
2032
void PriorityDialog::pressOk()
2133
{
2234
bool l_ok;
23-
int l_newPrio=ui.priority->text().toInt(&l_ok);
35+
int l_newPrio=ui.newPriority->text().toInt(&l_ok);
2436
if(l_ok){
25-
errno=0;
26-
setpriority(PRIO_PROCESS,pid,l_newPrio);
27-
if(errno ==0){
28-
close();
37+
if(l_newPrio <0){
38+
errorMessage(i18n("Invalid priority, value must be equal or biger than 0"));
39+
} else{
40+
errno=0;
41+
int l_return=setpriority(PRIO_PROCESS,pid,l_newPrio);
42+
printf("Set priority of pid=%d to %d return=%d \n",pid,l_newPrio,l_return);
43+
if(errno ==0){
44+
close();
45+
} else {
46+
errorMessage(strerror(errno));
47+
}
2948
}
30-
printf("Error=%d\n",errno);
49+
} else {
50+
errorMessage(i18n("Invalid number"));
3151
}
3252

3353
}

‎src/gui/priority.h

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class PriorityDialog:public QDialog
1212
private slots:
1313
void pressOk();
1414
void pressCancel();
15+
void errorMessage(QString p_message);
1516
public:
1617
Ui::PriorityDialog ui;
1718
PriorityDialog(TProcessInfo *p_info);

‎src/gui/procgui.cpp

+21-3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ TProcGui::TProcGui(QWidget *parent) : QMainWindow(parent), ui(new Ui::procgui)
8686
}
8787
TSortProxy *sortProxy=new TSortProxy(g_config.getFields(),this);
8888
ui->processList->setModel(sortProxy);
89+
ui->autoRefresh->setCheckState(Qt::Checked);
90+
8991
connect(ui->action_Exit,SIGNAL(triggered()),qApp,SLOT(quit()));
9092
connect(ui->actionFields,SIGNAL(triggered()),this,SLOT(fieldsDialog()));
9193
connect(ui->actionAbout,SIGNAL(triggered()), this,SLOT(about()));
@@ -96,6 +98,7 @@ TProcGui::TProcGui(QWidget *parent) : QMainWindow(parent), ui(new Ui::procgui)
9698
connect(ui->detailsButton,SIGNAL(clicked()),this,SLOT(showDetails()));
9799
connect(ui->displayAsTree,SIGNAL(clicked()),this,SLOT(checkDisplayAsTree()));
98100
connect(ui->priority,SIGNAL(clicked()),this,SLOT(showPriorityDialog()));
101+
connect(ui->autoRefresh,SIGNAL(clicked()),this,SLOT(clickAutoRefresh()));
99102
ui->displayAsTree->setCheckState(g_config.getDisplayAsTree()?Qt::Checked:Qt::Unchecked);
100103
ui->processList->setItemDelegate(new TGridDelegate(ui->processList));
101104
userSelection=new QTableView(this);
@@ -104,7 +107,7 @@ TProcGui::TProcGui(QWidget *parent) : QMainWindow(parent), ui(new Ui::procgui)
104107
userSelection->setSelectionMode(QAbstractItemView::SingleSelection);
105108
userSelection->verticalHeader()->setVisible(false);
106109
refreshTimeout();
107-
refresh.setInterval(1024);
110+
refresh.setInterval(1000);
108111
refresh.start();
109112
}
110113

@@ -123,24 +126,39 @@ void TProcGui::about()
123126
l_about.exec();
124127
}
125128

129+
/**
130+
* Event fired when user clicks the autorefresh checkbox.
131+
* This method togles autorefresh
132+
*/
133+
void TProcGui::clickAutoRefresh()
134+
{
135+
if(ui->autoRefresh->checkState()==Qt::Checked){
136+
refresh.start();
137+
} else {
138+
refresh.stop();
139+
}
140+
}
141+
142+
126143
/**
127144
* Show the PropertyDialog for changing the proces priority
128145
*/
129146
void TProcGui::showPriorityDialog()
130147
{
131-
printf("Help\n");
132148
if(ui->processList->selectionModel()->selectedRows().count()>0){
149+
refresh.stop();
133150
pid_t l_pid=ui->processList->selectionModel()->selectedRows().first().data(Qt::UserRole+1).toUInt();
134151
TProcessInfo *l_info=processInfo->getByPid(l_pid);
135152
PriorityDialog l_dialog(l_info);
136153
l_dialog.exec();
154+
refresh.start();
155+
refreshTimeout();
137156
}
138157

139158

140159
}
141160

142161

143-
144162
/**
145163
* Fills/refresh the list with users. Before the refresh, the current selection is saved and restored after the refresh.
146164
* The list is sorted on the description. The associated data item is the user id.

‎src/gui/procgui.h

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ private slots:
3131
void checkDisplayAsTree();
3232
void showPriorityDialog();
3333
void about();
34+
void clickAutoRefresh();
3435
private:
3536
/**
3637
* Gui layout

‎src/gui/procinfodialog.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ void TProcInfoDialog::fillData(TProcessInfo *p_processInfo)
7070
ui.stime_label->setText(p_processInfo->getSTimeStr());
7171
ui.diffUTime_label->setText(QString::number(p_processInfo->getDiffUTime()));
7272
ui.diffSTime_label->setText(QString::number(p_processInfo->getDiffSTime()));
73+
ui.priority_label->setText(QString::number(p_processInfo->getPriority()));
74+
7375
QStandardItemModel *l_model=new QStandardItemModel(0,3,this);
7476
l_model->setHorizontalHeaderItem(0,new QStandardItem(i18n("Pid")));
7577
l_model->setHorizontalHeaderItem(1,new QStandardItem(i18n("Command")));

‎src/ui/procgui.ui

+7
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@
8686
</property>
8787
</widget>
8888
</item>
89+
<item>
90+
<widget class="QCheckBox" name="autoRefresh">
91+
<property name="text">
92+
<string>refresh</string>
93+
</property>
94+
</widget>
95+
</item>
8996
<item>
9097
<widget class="QCheckBox" name="displayAsTree">
9198
<property name="text">

‎src/ui/procinfodialog.ui

+30-10
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@
224224
</property>
225225
</widget>
226226
</item>
227-
<item row="5" column="0">
227+
<item row="6" column="0">
228228
<widget class="QLabel" name="label_8">
229229
<property name="font">
230230
<font>
@@ -237,14 +237,14 @@
237237
</property>
238238
</widget>
239239
</item>
240-
<item row="5" column="1">
240+
<item row="6" column="1">
241241
<widget class="QLabel" name="startTime_label">
242242
<property name="text">
243243
<string>TextLabel</string>
244244
</property>
245245
</widget>
246246
</item>
247-
<item row="6" column="0">
247+
<item row="7" column="0">
248248
<widget class="QLabel" name="label_11">
249249
<property name="font">
250250
<font>
@@ -257,14 +257,14 @@
257257
</property>
258258
</widget>
259259
</item>
260-
<item row="6" column="1">
260+
<item row="7" column="1">
261261
<widget class="QLabel" name="vsize_label">
262262
<property name="text">
263263
<string>TextLabel</string>
264264
</property>
265265
</widget>
266266
</item>
267-
<item row="7" column="0">
267+
<item row="8" column="0">
268268
<widget class="QLabel" name="label_12">
269269
<property name="font">
270270
<font>
@@ -277,14 +277,14 @@
277277
</property>
278278
</widget>
279279
</item>
280-
<item row="7" column="1">
280+
<item row="8" column="1">
281281
<widget class="QLabel" name="rss_label">
282282
<property name="text">
283283
<string>TextLabel</string>
284284
</property>
285285
</widget>
286286
</item>
287-
<item row="8" column="0">
287+
<item row="9" column="0">
288288
<widget class="QLabel" name="label_14">
289289
<property name="font">
290290
<font>
@@ -297,7 +297,7 @@
297297
</property>
298298
</widget>
299299
</item>
300-
<item row="8" column="1">
300+
<item row="9" column="1">
301301
<layout class="QHBoxLayout" name="horizontalLayout">
302302
<property name="leftMargin">
303303
<number>5</number>
@@ -331,7 +331,7 @@
331331
</item>
332332
</layout>
333333
</item>
334-
<item row="9" column="0">
334+
<item row="10" column="0">
335335
<widget class="QLabel" name="label_13">
336336
<property name="font">
337337
<font>
@@ -344,7 +344,7 @@
344344
</property>
345345
</widget>
346346
</item>
347-
<item row="9" column="1">
347+
<item row="10" column="1">
348348
<layout class="QHBoxLayout" name="horizontalLayout_2">
349349
<property name="leftMargin">
350350
<number>5</number>
@@ -378,6 +378,26 @@
378378
</item>
379379
</layout>
380380
</item>
381+
<item row="5" column="0">
382+
<widget class="QLabel" name="label_17">
383+
<property name="font">
384+
<font>
385+
<weight>75</weight>
386+
<bold>true</bold>
387+
</font>
388+
</property>
389+
<property name="text">
390+
<string>Priority</string>
391+
</property>
392+
</widget>
393+
</item>
394+
<item row="5" column="1">
395+
<widget class="QLabel" name="priority_label">
396+
<property name="text">
397+
<string>TextLabel</string>
398+
</property>
399+
</widget>
400+
</item>
381401
</layout>
382402
</item>
383403
</layout>

0 commit comments

Comments
 (0)
Please sign in to comment.