-
Notifications
You must be signed in to change notification settings - Fork 0
/
jobman.cpp
executable file
·750 lines (697 loc) · 24.1 KB
/
jobman.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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
// Copyright 2022-present Contributors to the jobman project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/mikaelsundell/jobman
#include "jobman.h"
#include "dropfilter.h"
#include "error.h"
#include "eventfilter.h"
#include "icctransform.h"
#include "mac.h"
#include "monitor.h"
#include "options.h"
#include "preferences.h"
#include "preset.h"
#include "process.h"
#include "question.h"
#include "queue.h"
#include <QAction>
#include <QDir>
#include <QFile>
#include <QFileDialog>
#include <QDesktopServices>
#include <QList>
#include <QMessageBox>
#include <QPointer>
#include <QProcess>
#include <QRegularExpression>
#include <QSettings>
#include <QSharedPointer>
#include <QStandardPaths>
#include <QTimer>
#include <QThread>
#include <QWindow>
#include <QDebug>
// generated files
#include "ui_about.h"
#include "ui_jobman.h"
class JobmanPrivate : public QObject
{
Q_OBJECT
public:
JobmanPrivate();
void init();
void stylesheet();
void profile();
void activate();
void deactivate();
void enable(bool enable);
bool eventFilter(QObject* object, QEvent* event);
void loadSettings();
void saveSettings();
public Q_SLOTS:
void loadPresets();
void togglePreset();
void toggleFiledrop();
void showMonitor();
void showOptions();
void run(const QList<QString>& files);
void jobProcessed(const QUuid& uuid);
void addFiles();
void refreshPresets();
void openPreset();
void openPresetfrom();
void openSaveto();
void showSaveto();
void setSaveto(const QString& text);
void saveToChanged(const QString& text);
void createFolderChanged(int state);
void presetsChanged(int index);
void threadsChanged(int index);
void showAbout();
void showPreferences();
void openGithubReadme();
void openGithubIssues();
Q_SIGNALS:
void readOnly(bool readOnly);
public:
class About : public QDialog
{
public: About(QWidget *parent = nullptr)
: QDialog(parent)
{
QScopedPointer<Ui_About> about;
about.reset(new Ui_About());
about->setupUi(this);
about->name->setText(MACOSX_BUNDLE_BUNDLE_NAME);
about->version->setText(MACOSX_BUNDLE_LONG_VERSION_STRING);
about->copyright->setText(MACOSX_BUNDLE_COPYRIGHT);
QString url = GITHUBURL;
about->github->setText(QString("Github project: <a href='%1'>%1</a>").arg(url));
about->github->setTextFormat(Qt::RichText);
about->github->setTextInteractionFlags(Qt::TextBrowserInteraction);
about->github->setOpenExternalLinks(true);
QFile file(":/files/resources/Copyright.txt");
file.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream in(&file);
QString text = in.readAll();
file.close();
about->licenses->setText(text);
}
};
QString replacePattern(const QString& input, const QString& pattern, const QFileInfo& inputinfo);
QString replaceInput(const QString& input, const QFileInfo& inputinfo, const QFileInfo& outputinfo);
int width;
int height;
QSize size;
QString presetselected;
QString presetfrom;
QString saveto;
QString filesfrom;
bool createfolders;
QMap<QString, QList<QUuid>> processedfiles;
QPointer<Queue> queue;
QPointer<Jobman> window;
QScopedPointer<About> about;
QScopedPointer<Monitor> monitor;
QScopedPointer<Options> options;
QScopedPointer<Preferences> preferences;
QScopedPointer<Dropfilter> dropfilter;
QScopedPointer<Eventfilter> presetfilter;
QScopedPointer<Eventfilter> filedropfilter;
QScopedPointer<Ui_Jobman> ui;
};
JobmanPrivate::JobmanPrivate()
: width(128)
, height(128)
{
qRegisterMetaType<QSharedPointer<Preset>>("QSharedPointer<Preset>");
}
void
JobmanPrivate::init()
{
mac::setDarkAppearance();
// icc profile
ICCTransform* transform = ICCTransform::instance();
QDir resources(QApplication::applicationDirPath() + "/../Resources");
QString inputProfile = resources.filePath("sRGB2014.icc"); // built-in Qt input profile
transform->setInputProfile(inputProfile);
profile();
// queue
queue = Queue::instance();
// ui
ui.reset(new Ui_Jobman());
ui->setupUi(window);
// about
about.reset(new About(window.data()));
// monitor
monitor.reset(new Monitor(window.data()));
monitor->setModal(false);
// options
options.reset(new Options(window.data()));
// preferences
preferences.reset(new Preferences(window.data()));
// settings
loadSettings();
// layout
// needed to keep .ui fixed size from setupUi
window->setFixedSize(window->size());
// event filter
window->installEventFilter(this);
// display filter
presetfilter.reset(new Eventfilter);
ui->presetBar->installEventFilter(presetfilter.data());
// color filter
filedropfilter.reset(new Eventfilter);
ui->filedropBar->installEventFilter(filedropfilter.data());
// drop filter
dropfilter.reset(new Dropfilter);
ui->saveTo->installEventFilter(dropfilter.data());
// progress
ui->fileprogress->hide();
// connect
connect(ui->togglePreset, &QPushButton::pressed, this, &JobmanPrivate::togglePreset);
connect(ui->toggleFiledrop, &QPushButton::pressed, this, &JobmanPrivate::toggleFiledrop);
connect(presetfilter.data(), &Eventfilter::pressed, ui->togglePreset, &QPushButton::click);
connect(filedropfilter.data(), &Eventfilter::pressed, ui->toggleFiledrop, &QPushButton::click);
connect(ui->addfiles, &QAction::triggered, this, &JobmanPrivate::addFiles);
connect(ui->refreshPresets, &QPushButton::clicked, this, &JobmanPrivate::refreshPresets);
connect(ui->openPreset, &QPushButton::clicked, this, &JobmanPrivate::openPreset);
connect(ui->openPresetfrom, &QPushButton::clicked, this, &JobmanPrivate::openPresetfrom);
connect(ui->openSaveto, &QPushButton::clicked, this, &JobmanPrivate::openSaveto);
connect(ui->showSaveto, &QPushButton::clicked, this, &JobmanPrivate::showSaveto);
connect(dropfilter.data(), &Dropfilter::textChanged, this, &JobmanPrivate::saveToChanged);
connect(ui->createFolders, &QCheckBox::stateChanged, this, &JobmanPrivate::createFolderChanged);
connect(ui->filedrop, &Filedrop::filesDropped, this, &JobmanPrivate::run);
connect(ui->presets, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &JobmanPrivate::presetsChanged);
connect(ui->threads, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &JobmanPrivate::threadsChanged);
connect(ui->about, &QAction::triggered, this, &JobmanPrivate::showAbout);
connect(ui->showMonitor, &QAction::triggered, this, &JobmanPrivate::showMonitor);
connect(ui->monitor, &QPushButton::clicked, this, &JobmanPrivate::showMonitor);
connect(ui->showOptions, &QAction::triggered, this, &JobmanPrivate::showOptions);
connect(ui->options, &QPushButton::clicked, this, &JobmanPrivate::showOptions);
connect(ui->preferences, &QAction::triggered, this, &JobmanPrivate::showPreferences);
connect(ui->openGithubReadme, &QAction::triggered, this, &JobmanPrivate::openGithubReadme);
connect(ui->openGithubIssues, &QAction::triggered, this, &JobmanPrivate::openGithubIssues);
connect(queue.data(), &Queue::jobProcessed, this, &JobmanPrivate::jobProcessed);
size = window->size();
// threads
int threads = QThread::idealThreadCount();
for (int i = 1; i <= threads; ++i) {
ui->threads->addItem(QString::number(i), i);
}
// cpu
QTimer *timer = new QTimer(window.data());
QObject::connect(timer, &QTimer::timeout, [&]() {
if (ui->fileprogress->maximum()) {
Process process;
process.run("ps", QStringList() << "-A" << "-o" << "%cpu");
process.wait();
QString output = process.standardOutput();
QStringList lines = output.split("\n", Qt::SkipEmptyParts);
double totalCpu = 0;
for (int i = 1; i < lines.size(); ++i) { // Starting at 1 skips the header line
totalCpu += lines[i].trimmed().toDouble();
}
int numberOfCores = QThread::idealThreadCount();
double normalizedCpuUsage = totalCpu / numberOfCores;
ui->cpu->setText(QString("CPU: %1%").arg(normalizedCpuUsage, 0, 'f', 0));
} else {
ui->cpu->setText(QString(""));
}
});
timer->start(1000);
// stylesheet
stylesheet();
// debug
#ifdef QT_DEBUG
QMenu* menu = ui->menubar->addMenu("Debug");
{
QAction* action = new QAction("Reload stylesheet...", this);
action->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_S));
menu->addAction(action);
connect(action, &QAction::triggered, [&]() {
this->stylesheet();
});
}
#endif
// presets
QTimer::singleShot(0, [this]() { this->loadPresets(); });
}
void
JobmanPrivate::stylesheet()
{
QDir resources(QApplication::applicationDirPath());
QFile stylesheet(resources.absolutePath() + "/../Resources/App.css");
stylesheet.open(QFile::ReadOnly);
QString qss = stylesheet.readAll();
QRegularExpression hslRegex("hsl\\(\\s*(\\d+)\\s*,\\s*(\\d+)%\\s*,\\s*(\\d+)%\\s*\\)");
QString transformqss = qss;
QRegularExpressionMatchIterator i = hslRegex.globalMatch(transformqss);
while (i.hasNext()) {
QRegularExpressionMatch match = i.next();
if (match.hasMatch()) {
if (!match.captured(1).isEmpty() &&
!match.captured(2).isEmpty() &&
!match.captured(3).isEmpty())
{
int h = match.captured(1).toInt();
int s = match.captured(2).toInt();
int l = match.captured(3).toInt();
QColor color = QColor::fromHslF(h / 360.0f, s / 100.0f, l / 100.0f);
// icc profile
ICCTransform* transform = ICCTransform::instance();
color = transform->map(color.rgb());
QString hsl = QString("hsl(%1, %2%, %3%)")
.arg(color.hue() == -1 ? 0 : color.hue())
.arg(static_cast<int>(color.hslSaturationF() * 100))
.arg(static_cast<int>(color.lightnessF() * 100));
transformqss.replace(match.captured(0), hsl);
}
}
}
qApp->setStyleSheet(transformqss);
}
void
JobmanPrivate::profile()
{
QString outputProfile = mac::grabIccProfileUrl(window->winId());
// icc profile
ICCTransform* transform = ICCTransform::instance();
transform->setOutputProfile(outputProfile);
}
void
JobmanPrivate::activate()
{
enable(true);
}
void
JobmanPrivate::deactivate()
{
enable(false);
}
void
JobmanPrivate::addFiles()
{
QStringList filenames = QFileDialog::getOpenFileNames(
window.data(),
tr("Select files"),
filesfrom,
tr("All files (*)")
);
if (!filenames.isEmpty()) {
QFileInfo fileInfo(filenames.first());
filesfrom = fileInfo.absolutePath();
run(filenames);
}
}
void
JobmanPrivate::enable(bool enable)
{
ui->openPreset->setEnabled(enable);
ui->refreshPresets->setEnabled(enable);
ui->filedrop->setEnabled(enable);
ui->fileprogress->setEnabled(enable);
}
bool
JobmanPrivate::eventFilter(QObject* object, QEvent* event)
{
if (event->type() == QEvent::ScreenChangeInternal) {
profile();
stylesheet();
}
if (event->type() == QEvent::Close) {
if (ui->fileprogress->value()) {
if (Question::askQuestion(window.data(), "Jobs are in progress, are you sure you want to quit?")) {
saveSettings();
return true;
} else {
event->ignore();
return true;
}
}
saveSettings();
return true;
}
return QObject::eventFilter(object, event);
}
void
JobmanPrivate::loadSettings()
{
QDir applicationPath(QApplication::applicationDirPath());
QString documents = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
QString presets = applicationPath.absolutePath() + "/../Presets";
QSettings settings(MACOSX_BUNDLE_GUI_IDENTIFIER, "Jobman");
filesfrom = settings.value("filesFrom", documents).toString();
presetselected = settings.value("presetselected", "").toString();
presetfrom = settings.value("presetFrom", presets).toString();
saveto = settings.value("saveTo", documents).toString();
createfolders = settings.value("createFolders", false).toBool();
// ui
setSaveto(saveto);
ui->createFolders->setChecked(createfolders);
}
void
JobmanPrivate::saveSettings()
{
QSettings settings(MACOSX_BUNDLE_GUI_IDENTIFIER, "Jobman");
settings.setValue("filesFrom", filesfrom);
// presets
if (ui->presets->count()) {
QSharedPointer<Preset> preset = ui->presets->currentData().value<QSharedPointer<Preset>>();
if (!preset.isNull()) { // skip "No presets found"
settings.setValue("presetselected", preset->filename());
}
}
settings.setValue("presetFrom", presetfrom);
settings.setValue("saveTo", saveto);
settings.setValue("createFolders", createfolders);
}
void
JobmanPrivate::loadPresets()
{
ui->presets->clear();
QDir presets(presetfrom);
QFileInfoList presetfiles = presets.entryInfoList(QStringList("*.json"));
QString error;
if (presetfiles.count() > 0) {
for(QFileInfo presetfile : presetfiles) {
QSharedPointer<Preset> preset(new Preset());
QString filename = presetfile.absoluteFilePath();
if (preset->read(filename)) {
ui->presets->addItem(preset->name(), QVariant::fromValue(preset));
if (filename == presetselected) {
ui->presets->setCurrentIndex(ui->presets->count() - 1);
}
} else {
if (error.length() > 0) {
error += "\n";
}
error += QString("Could not load preset from file:\n"
"%1\n\n"
"Error:\n"
"%2\n")
.arg(presetfile.absoluteFilePath())
.arg(preset->error());
}
}
if (error.length() > 0) {
Error::showError(window.data(), "Could not load all presets", error);
}
activate();
} else {
ui->presets->addItem("No presets found");
deactivate();
}
}
QString
JobmanPrivate::replacePattern(const QString& input, const QString& pattern, const QFileInfo& fileinfo)
{
QString result = input;
QList<QPair<QString, QString>> replacements = {
{QString("%%1dir%").arg(pattern), fileinfo.absolutePath()},
{QString("%%1file%").arg(pattern), fileinfo.absoluteFilePath()},
{QString("%%1ext%").arg(pattern), fileinfo.suffix()},
{QString("%%1base%").arg(pattern), fileinfo.baseName()}
};
for (const auto& replacement : replacements) {
result.replace(replacement.first, replacement.second);
}
return result;
}
QString
JobmanPrivate::replaceInput(const QString& input, const QFileInfo& inputinfo, const QFileInfo& outputinfo)
{
return replacePattern(replacePattern(input, "input", inputinfo), "output", outputinfo);
}
void
JobmanPrivate::run(const QList<QString>& files)
{
QSharedPointer<Preset> preset = ui->presets->currentData().value<QSharedPointer<Preset>>();
QString outputDir = saveto;
processedfiles.clear();
int count = 0;
for(const QString& file : files) {
QMap<QString, QUuid> jobuuids;
QList<QPair<QSharedPointer<Job>, QString>> dependentjobs;
QFileInfo inputinfo(file);
for(const Task& task : preset->tasks()) {
QString extension = replacePattern(task.extension, "input", inputinfo);
QString outputdir;
if (createfolders) {
outputdir =
outputDir +
"/" +
inputinfo.baseName();
} else {
outputdir = outputDir;
}
QString outputfile =
outputdir +
"/" +
inputinfo.baseName() +
"." +
extension;
QFileInfo outputinfo(outputfile);
QString command = replaceInput(task.command, inputinfo, outputinfo);
QStringList argumentlist = task.arguments.split(' ');
for(QString& argument : argumentlist) {
argument = replaceInput(argument, inputinfo, outputinfo);
}
QString startin = replaceInput(task.startin, inputinfo, outputinfo);
QSharedPointer<Job> job(new Job());
{
job->setId(task.id);
job->setFilename(inputinfo.fileName());
job->setName(task.name);
job->setCommand(command);
job->setArguments(argumentlist);
job->setStartin(startin);
job->setStatus(Job::Waiting);
}
job->setOutput(outputdir);
if (task.dependson.isEmpty()) {
QUuid uuid = queue->submit(job);
count++;
if (!processedfiles.contains(file)) {
processedfiles.insert(file, QList<QUuid>());
}
processedfiles[file].append(uuid);
jobuuids[task.id] = uuid;
} else {
dependentjobs.append(qMakePair(job, task.dependson));
}
}
for (QPair<QSharedPointer<Job>, QString> depedentjob : dependentjobs) {
QSharedPointer<Job> job = depedentjob.first;
QString dependentid = depedentjob.second;
if (jobuuids.contains(dependentid)) {
job->setDependson(jobuuids[dependentid]);
QUuid uuid = queue->submit(job);
if (!processedfiles.contains(file)) {
processedfiles.insert(file, QList<QUuid>());
}
processedfiles[file].append(uuid);
jobuuids[job->id()] = uuid;
count++;
} else {
QString status = QString("Status:\n"
"Dependency not found for job: %1\n")
.arg(job->name());
job->setLog(status);
job->setStatus(Job::Failed);
return;
}
}
}
ui->fileprogress->setMaximum(ui->fileprogress->maximum() + count);
if (!ui->fileprogress->isVisible()) {
ui->fileprogress->show();
ui->idleprogress->hide();
}
}
void
JobmanPrivate::jobProcessed(const QUuid& uuid)
{
bool found = false;
QStringList files = processedfiles.keys();
for (const QString& file : files) {
if (processedfiles[file].contains(uuid)) {
processedfiles[file].removeAll(uuid);
if (processedfiles[file].isEmpty()) {
processedfiles.remove(file);
}
found = true;
}
}
if (found) { // test if dropped
int value = ui->fileprogress->value() + 1;
if (value == ui->fileprogress->maximum()) {
ui->fileprogress->setValue(0);
ui->fileprogress->setMaximum(0);
ui->fileprogress->hide();
ui->idleprogress->show();
} else {
ui->fileprogress->setValue(value);
ui->fileprogress->setToolTip(QString("Completed %1 of %2").arg(ui->fileprogress->value()).arg(ui->fileprogress->maximum()));
}
}
}
void
JobmanPrivate::refreshPresets()
{
loadPresets();
}
void
JobmanPrivate::openPreset()
{
if (ui->presets->count()) {
QSharedPointer<Preset> preset = ui->presets->currentData().value<QSharedPointer<Preset>>();
QDesktopServices::openUrl(QUrl::fromLocalFile(preset->filename()));
}
}
void
JobmanPrivate::openPresetfrom()
{
QString dir = QFileDialog::getExistingDirectory(
window.data(),
tr("Open preset folder ..."),
presetfrom,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
);
if (!dir.isEmpty()) {
presetfrom = dir;
refreshPresets();
}
}
void
JobmanPrivate::openSaveto()
{
QString dir = QFileDialog::getExistingDirectory(
window.data(),
tr("Open savefolder ..."),
saveto,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
);
if (!dir.isEmpty()) {
saveto = dir;
setSaveto(saveto);
}
}
void
JobmanPrivate::showSaveto()
{
QDesktopServices::openUrl(QUrl::fromLocalFile(saveto));
}
void
JobmanPrivate::setSaveto(const QString& text)
{
QFontMetrics metrics(ui->saveTo->font());
ui->saveTo->setText(metrics.elidedText(text, Qt::ElideRight, ui->saveTo->maximumSize().width()));
}
void
JobmanPrivate::saveToChanged(const QString& text)
{
saveto = text;
}
void
JobmanPrivate::createFolderChanged(int state)
{
createfolders = (state == Qt::Checked);
}
void
JobmanPrivate::presetsChanged(int index)
{
QSharedPointer<Preset> preset = ui->presets->currentData().value<QSharedPointer<Preset>>();
bool enabled = false;
if (preset->options().size()) {
enabled = true;
}
ui->showOptions->setEnabled(enabled);
ui->options->setEnabled(enabled);
}
void
JobmanPrivate::threadsChanged(int index)
{
queue->setThreads(ui->threads->itemText(index).toInt());
}
void
JobmanPrivate::togglePreset()
{
int height = ui->presetWidget->height();
if (ui->togglePreset->isChecked()) {
ui->togglePreset->setIcon(QIcon(":/icons/resources/Collapse.png"));
ui->presetWidget->show();
window->setFixedSize(window->width(), size.height() + height);
} else {
ui->togglePreset->setIcon(QIcon(":/icons/resources/Expand.png"));
ui->presetWidget->hide();
window->setFixedSize(window->width(), size.height() - height);
}
size = window->size();
}
void
JobmanPrivate::toggleFiledrop()
{
int height = ui->filedropWidget->height();
if (ui->toggleFiledrop->isChecked()) {
ui->toggleFiledrop->setIcon(QIcon(":/icons/resources/Collapse.png"));
ui->filedropWidget->show();
window->setFixedSize(window->width(), size.height() + height);
} else {
ui->toggleFiledrop->setIcon(QIcon(":/icons/resources/Expand.png"));
ui->filedropWidget->hide();
window->setFixedSize(window->width(), size.height() - height);
}
size = window->size();
}
void
JobmanPrivate::showAbout()
{
about->exec();
}
void
JobmanPrivate::showMonitor()
{
if (monitor->isVisible()) {
monitor->raise();
} else {
monitor->show();
}
}
void
JobmanPrivate::showOptions()
{
QSharedPointer<Preset> preset = ui->presets->currentData().value<QSharedPointer<Preset>>();
options->update(preset);
options->exec();
}
void
JobmanPrivate::showPreferences()
{
preferences->exec();
}
void
JobmanPrivate::openGithubReadme()
{
QDesktopServices::openUrl(QUrl("https://github.com/mikaelsundell/jobman/blob/master/README.md"));
}
void
JobmanPrivate::openGithubIssues()
{
QDesktopServices::openUrl(QUrl("https://github.com/mikaelsundell/jobman/issues"));
}
#include "jobman.moc"
Jobman::Jobman()
: QMainWindow(nullptr,
Qt::WindowTitleHint |
Qt::CustomizeWindowHint |
Qt::WindowCloseButtonHint |
Qt::WindowMinimizeButtonHint)
, p(new JobmanPrivate())
{
p->window = this;
p->init();
}
Jobman::~Jobman()
{
}