-
Notifications
You must be signed in to change notification settings - Fork 0
/
sm3_config.cpp
410 lines (317 loc) · 13.4 KB
/
sm3_config.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
//! \file sm3_config.cpp
#include "sysmon3.h"
#include "sm3_config.h"
#include "sm3_font.h"
#include "sm3_temps.h"
SM_Config::SM_Config( sysmon3* parent )
{
mainWindow = parent;
server = parent->server;
settings = &parent->settings;
QString familyKey = server + "-fontFamily";
QString family = settings->value( familyKey, "DejaVu Sans" ).toString();
QString sizeKey = server + "-fontSize";
int fontSize = settings->value( sizeKey, 12 ).toInt();
QFont oldfont = QFont( family, fontSize );
widgets = new SM_Widgets( oldfont );
setWindowTitle( "sysmon3 Configuration" );
// Directories
QBoxLayout* topbox = new QVBoxLayout( this );
topbox->setContentsMargins ( 2, 2, 2, 2 );
topbox->setSpacing ( 2 );
version = widgets->sm_label( "Version: " SMVERSION );
topbox->addWidget( version );
int row = 0;
QGridLayout* mainEntries = new QGridLayout();
// refresh interval
int refresh = settings->value( server + "-refreshInterval", "1" ).toInt();
lbl_refresh = widgets->sm_label( tr( "Refresh Interval:" ) );
SBrefresh = widgets->sm_spinBox( refresh );
SBrefresh->setRange( 1, 9 );
PBrefresh = widgets->sm_pushbutton( tr( "Help" ) );
lbl_refresh->setFont( oldfont );
SBrefresh ->setFont( oldfont );
PBrefresh ->setFont( oldfont );
connect( PBrefresh, SIGNAL( clicked() ), this, SLOT( refresh_help() ) );
mainEntries->addWidget( lbl_refresh, row, 0 );
mainEntries->addWidget( SBrefresh, row, 1 );
mainEntries->addWidget( PBrefresh, row++, 2 );
// time
QString timeFormat = settings->value( server + "-timeFormat", "HH:mm:ss" ).toString();
bool timeChecked = settings->value( server + "-useTime", true ).toBool();
QGridLayout* CBTimeLayout = widgets->sm_checkbox( "time", CBtime, timeChecked );
LEtime = widgets->sm_lineedit( timeFormat );
PBtime = widgets->sm_pushbutton( tr( "Help" ) );
CBtime->setFont( oldfont );
LEtime->setFont( oldfont );
PBtime->setFont( oldfont );
connect( PBtime, SIGNAL( clicked() ), this, SLOT( time_help() ) );
mainEntries->addLayout( CBTimeLayout, row, 0 );
mainEntries->addWidget( LEtime, row, 1 );
mainEntries->addWidget( PBtime, row++, 2 );
// date
QString dateFormat = settings->value( server + "-dateFormat", "ddd d MMM" ).toString();
bool dateChecked = settings->value( server + "-useDate", true ).toBool();
QGridLayout* CBDateLayout = widgets->sm_checkbox( "date", CBdate, dateChecked );
LEdate = widgets->sm_lineedit( dateFormat );
PBdate = widgets->sm_pushbutton( tr( "Help" ) );
CBdate->setFont( oldfont );
LEdate->setFont( oldfont );
PBdate->setFont( oldfont );
connect( PBdate, SIGNAL( clicked() ), this, SLOT( date_help() ) );
mainEntries->addLayout( CBDateLayout, row, 0 );
mainEntries->addWidget( LEdate, row, 1 );
mainEntries->addWidget( PBdate, row++, 2 );
// uptime
bool uptimeChecked = settings->value( server + "-useUptime", true ).toBool();
QGridLayout* CBuptimeLayout = widgets->sm_checkbox( "uptime", CBuptime, uptimeChecked );
PBuptime = widgets->sm_pushbutton( tr( "Help" ) );
CBuptime->setFont( oldfont );
PBuptime->setFont( oldfont );
connect( PBuptime, SIGNAL( clicked() ), this, SLOT( uptime_help() ) );
mainEntries->addLayout( CBuptimeLayout, row, 0 );
mainEntries->addWidget( PBuptime, row++, 2 );
// CPU Load
bool CPUchecked = settings->value( server + "-useCPU", true ).toBool();
bool CPUbar = settings->value( server + "-useCPUbar", true ).toBool();
QGridLayout* CBcpuLayout = widgets->sm_checkbox( "CPU Load", CBcpu, CPUchecked );
QGridLayout* CBcpuBarLayout = widgets->sm_checkbox( "CPU Bar", CBcpuBar, CPUbar );
PBcpu = widgets->sm_pushbutton( tr( "Help" ) );
CBcpu ->setFont( oldfont );
CBcpuBar->setFont( oldfont );
PBcpu ->setFont( oldfont );
connect( PBcpu, SIGNAL( clicked() ), this, SLOT( cpu_help() ) );
mainEntries->addLayout( CBcpuLayout, row, 0 );
mainEntries->addLayout( CBcpuBarLayout, row, 1 );
mainEntries->addWidget( PBcpu, row++, 2 );
// Memory display
bool memoryChecked = settings->value( server + "-useMemory", true ).toBool();
QGridLayout* CBmemoryLayout = widgets->sm_checkbox( "Memory Bar", CBmemory, memoryChecked );
PBmemory = widgets->sm_pushbutton( tr( "Help" ) );
CBmemory->setFont( oldfont );
PBmemory->setFont( oldfont );
connect( PBmemory, SIGNAL( clicked() ), this, SLOT( memory_help() ) );
mainEntries->addLayout( CBmemoryLayout, row, 0 );
mainEntries->addWidget( PBmemory, row++, 2 );
topbox->addLayout( mainEntries );
// Misc Settings
row = 0;
QGridLayout* otherSettings = new QGridLayout();
// Font Preferences
lbl_font = widgets->sm_label( tr( "Font Preferences:" ) );
pb_font = widgets->sm_pushbutton( tr( "Change Font" ) );
otherSettings->addWidget( lbl_font, row, 0 );
otherSettings->addWidget( pb_font, row++, 1 );
connect( pb_font, SIGNAL( clicked() ), this, SLOT( update_font() ) );
// Color Preferences
lbl_color = widgets->sm_label( tr( "Color Preferences:" ) );
pb_color = widgets->sm_pushbutton( tr( "Change Colors" ) );
otherSettings->addWidget( lbl_color, row, 0 );
otherSettings->addWidget( pb_color, row++, 1 );
connect( pb_color, SIGNAL( clicked() ), this, SLOT( update_colors() ) );
// Temperature Preferences
lbl_temps = widgets->sm_label( tr( "Temperature Preferences:" ) );
pb_temps = widgets->sm_pushbutton( tr( "Change Temps" ) );
otherSettings->addWidget( lbl_temps, row, 0 );
otherSettings->addWidget( pb_temps, row++, 1 );
connect( pb_temps, SIGNAL( clicked() ), this, SLOT( update_temps() ) );
// Pushbuttons
//pb_help = sm_pushbutton( tr( "Help" ) );
//connect( pb_help, SIGNAL( clicked() ), this, SLOT( help() ) );
pb_apply = widgets->sm_pushbutton( tr( "Apply" ) );
connect( pb_apply, SIGNAL( clicked() ), this, SLOT( apply() ) );
pb_exit = widgets->sm_pushbutton( tr( "Exit" ) );
connect( pb_exit, SIGNAL( clicked() ), this, SLOT( close() ) );
QBoxLayout* buttons = new QHBoxLayout();
buttons->addWidget( pb_apply );
// buttons->addWidget( pb_help );
buttons->addWidget( pb_exit );
topbox->addLayout( otherSettings );
topbox->addLayout( buttons );
setLayout( topbox);
update_local();
// Place the window to the left or right of the parent
// depending on the position on the screen
QRect parentGeom = parent->geometry();
int width = this->width();
int newx;
if ( parentGeom.left() - width - 100 < 0 )
newx = parentGeom.x() + parentGeom.width() + 100;
else
newx = parentGeom.x() - width - 100;
this->move( newx, parentGeom.y() );
}
//void SM_Config::help( void )
//{
// showhelp.show_help( "config.html" );
//}
// Display refresh help info
void SM_Config::refresh_help( void )
{
QString* text = new QString(
"Set this value to the desired refresh interval.\n" );
msg_box( text, 60 );
}
// Display time help info
void SM_Config::time_help( void )
{
QString* text = new QString(
"Select how time is displayed.\n"
"Format:\n"
"h The hour without a leading zero\n"
"hh The hour with a leading zero\n"
"H The hour without a leading zero\n"
"HH The hour with a leading zero\n"
"m The minute without a leading zero\n"
"mm The minute with a leading zero\n"
"s The whole second, without any leading zero\n"
"ss The whole second, with a leading zero\n"
"AP or A Use AM/PM display.\n"
"ap or a Use am/pm display.\n"
"t The timezone (for example 'CEST')" );
msg_box( text, 60 );
}
// Display date help info
void SM_Config::date_help( void )
{
QString* text = new QString(
"Select how date is displayed.\n"
"Format:\n"
"d The day as a number without a leading zero (1 to 31)\n"
"dd The day as a number with a leading zero (01 to 31)\n"
"ddd The abbreviated localized day name (e.g. 'Mon' to 'Sun')\n"
"dddd The long localized day name (e.g. 'Monday' to 'Sunday').\n"
"M The month as a number without a leading zero (1 to 12)\n"
"MM The month as a number with a leading zero (01 to 12)\n"
"MMM The abbreviated month name (e.g. 'Jan' to 'Dec').\n"
"MMMM The long month name (e.g. 'January' to 'December').\n"
"yy The year as a two digit number (00 to 99)\n"
"yyyy The year as a four digit number.\n" );
msg_box( text, 60 );
}
// Display cpu help info
void SM_Config::cpu_help( void )
{
QString* text = new QString(
"Select whether CPU Load and/or CPU Progress bar is displayed." );
msg_box( text, 45 );
}
// Display uptime help info
void SM_Config::uptime_help( void )
{
QString* text = new QString(
"Select whether uptime is displayed." );
msg_box( text, 45 );
}
// Display memory usage help info
void SM_Config::memory_help( void )
{
QString* text = new QString(
"Select whether memory usage is displayed." );
msg_box( text, 45 );
}
// Present text in a QMessageBox with specified width in characters
void SM_Config::msg_box( QString* text, int width )
{
// Trying to get the message box wider than about 60 characters
// does not seem to work
QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
int boxWidth = QFontMetrics( font ).averageCharWidth() * width;
QMessageBox MB;
QSpacerItem* spacer = new QSpacerItem( boxWidth, 0, QSizePolicy::Minimum,
QSizePolicy::Expanding );
MB.setText( *text );
MB.setFont( font );
QGridLayout* MBlayout = (QGridLayout*)MB.layout();
MBlayout->addItem( spacer, MBlayout->rowCount(), 0, 1, MBlayout->columnCount() );
MB.exec();
}
// Relay response from update_colors()
void SM_Config::sendColors( void )
{
//QMessageBox::information(this, "Test", "sm_config received update colors" );
emit updateColors();
}
// Relay response from update_Temps()
void SM_Config::sendTemps( void )
{
//QMessageBox::information(this, "Test", "sm_config received update temps" );
emit updateTemps();
}
// Relay response from update_font()
void SM_Config::sendFonts( void )
{
//QMessageBox::information(this, "Test", "sm_config received update font" );
// Update fonts here also
update_local();
emit updateFonts();
}
void SM_Config::update_font( void )
{
//SM_Font* font = new SM_Font( server, settings );
SM_Font* font = new SM_Font( mainWindow );
font->setWindowModality( Qt::WindowModal );
font->show();
connect( font, SIGNAL( updateFonts() ), this, SLOT( sendFonts() ) );
}
void SM_Config::update_colors( void )
{
//SM_Color* colors = new SM_Color( server, settings );
SM_Color* colors = new SM_Color( mainWindow );
colors->setWindowModality( Qt::WindowModal );
colors->show();
connect( colors, SIGNAL( updateColors() ), this, SLOT( sendColors() ) );
}
void SM_Config::update_temps( void )
{
//SM3_Temps* temps = new SM3_Temps( server, settings, data );
SM3_Temps* temps = new SM3_Temps( mainWindow );
temps->setWindowModality( Qt::WindowModal );
temps->show();
connect( temps, SIGNAL( updateTemps() ), this, SLOT( sendTemps() ) );
}
void SM_Config::update_local( void )
{
// Update local widgets
QFont font = QFont( settings->value( server + "-fontFamily", "DejaVu Sans" ).toString(),
settings->value( server + "-fontSize" , 12 ).toInt() );
version ->setFont( font );
pb_font ->setFont( font );
pb_color->setFont( font );
pb_temps->setFont( font );
pb_apply->setFont( font );
pb_exit ->setFont( font );
CBtime ->setFont( font );
CBdate ->setFont( font );
CBuptime->setFont( font );
CBcpu ->setFont( font );
CBcpuBar->setFont( font );
CBmemory->setFont( font );
PBrefresh->setFont( font );
PBtime ->setFont( font );
PBdate ->setFont( font );
PBuptime->setFont( font );
PBcpu ->setFont( font );
PBmemory->setFont( font );
SBrefresh->setFont( font );
LEtime ->setFont( font );
LEdate ->setFont( font );
lbl_refresh->setFont( font );
lbl_font ->setFont( font );
lbl_color->setFont( font );
lbl_temps->setFont( font );
}
void SM_Config::apply( void )
{
settings->setValue( server + "-refreshInterval", SBrefresh->value() );
settings->setValue( server + "-useTime", CBtime->isChecked() );
settings->setValue( server + "-useDate", CBdate->isChecked() );
settings->setValue( server + "-useUptime", CBuptime->isChecked() );
settings->setValue( server + "-useCPU", CBcpu->isChecked() );
settings->setValue( server + "-useCPUbar", CBcpuBar->isChecked() );
settings->setValue( server + "-useMemory", CBmemory->isChecked() );
settings->setValue( server + "-timeFormat", LEtime->text() );
settings->setValue( server + "-dateFormat", LEdate->text() );
settings->sync();
emit updateEntries();
}